forked from EndlessCheng/codeforces-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b2bb59
commit 19ae9dd
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
. "fmt" | ||
"io" | ||
"math" | ||
"strings" | ||
) | ||
|
||
// https://space.bilibili.com/206214 | ||
func CF708B(in io.Reader, out io.Writer) { | ||
var c00, c01, c10, c11 int | ||
Fscan(in, &c00, &c01, &c10, &c11) | ||
f := func(c int) int { | ||
x := (1 + int(math.Sqrt(float64(1+8*int64(c))))) / 2 | ||
if x*(x-1)/2 == c { | ||
return x | ||
} | ||
return -1 | ||
} | ||
c0, c1 := f(c00), f(c11) | ||
if c0 < 0 || c1 < 0 { | ||
Fprint(out, "Impossible") | ||
return | ||
} | ||
|
||
if c01 == 0 && c10 == 0 { | ||
if c00 > 0 && c11 > 0 { | ||
Fprint(out, "Impossible") | ||
} else if c11 == 0 { | ||
Fprint(out, strings.Repeat("0", c0)) | ||
} else { | ||
Fprint(out, strings.Repeat("1", c1)) | ||
} | ||
return | ||
} | ||
|
||
if c01+c10 != c0*c1 { | ||
Fprint(out, "Impossible") | ||
return | ||
} | ||
left1, right0 := c10/c0, c10%c0 | ||
ans := strings.Repeat("1", left1) + strings.Repeat("0", c0-right0) | ||
if right0 > 0 { | ||
ans += "1" + strings.Repeat("0", right0) | ||
c1-- | ||
} | ||
ans += strings.Repeat("1", c1-left1) | ||
Fprint(out, ans) | ||
} | ||
|
||
//func main() { CF708B(os.Stdin, os.Stdout) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/EndlessCheng/codeforces-go/main/testutil" | ||
"testing" | ||
) | ||
|
||
// https://codeforces.com/problemset/problem/708/B | ||
// https://codeforces.com/problemset/status/708/problem/B | ||
func TestCF708B(t *testing.T) { | ||
// just copy from website | ||
rawText := ` | ||
inputCopy | ||
1 2 3 4 | ||
outputCopy | ||
Impossible | ||
inputCopy | ||
1 2 2 1 | ||
outputCopy | ||
0110 | ||
inputCopy | ||
3 8 4 6 | ||
outputCopy | ||
1001011` | ||
testutil.AssertEqualCase(t, rawText, 0, CF708B) | ||
} |