Submission #33494861
Source Code Expand
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
func solveHonestly(n, c int, t, a []int) (ans []int) {
cc := c
for i := 1; i <= n; i++ {
for j := 0; j < i; j++ {
switch t[j] {
case 1:
cc &= a[j]
case 2:
cc |= a[j]
case 3:
cc ^= a[j]
}
}
ans = append(ans, cc)
}
return ans
}
func solve(n, c int, t, a []int) []int {
const maxBits = 30
var andBits, orBits, xorBits [maxBits]int
for j := 0; j < maxBits; j++ {
andBits[j] = -1
orBits[j] = -1
}
x := []int{c}
for i := 0; i < n; i++ {
//Aiの各桁を見て影響する値の更新
for j := 0; j < maxBits; j++ {
switch t[i] {
case 1:
if a[i]>>j&1 == 0 {
andBits[j] = i
xorBits[j] = 0
}
case 2:
if a[i]>>j&1 > 0 {
orBits[j] = i
xorBits[j] = 0
}
case 3:
if a[i]>>j&1 > 0 {
xorBits[j]++
}
}
}
//影響する値とxorを見て次のXを計算
var ncs [maxBits]int
nextX := 0
for j := 0; j < maxBits; j++ {
if andBits[j] < 0 && orBits[j] < 0 {
ncs[j] = x[i] >> j & 1
} else if andBits[j] < orBits[j] {
ncs[j] = 1
} else if andBits[j] > orBits[j] {
ncs[j] = 0
}
ncs[j] = (ncs[j] + xorBits[j]) % 2
if ncs[j] == 1 {
nextX |= 1 << j
}
}
x = append(x, nextX)
}
// X0を除いて、X1~Xnまでを解答として返す
return x[1:]
}
func main() {
buf := make([]byte, 1024*1024)
sc.Buffer(buf, bufio.MaxScanTokenSize)
sc.Split(bufio.ScanWords)
n, c := nextInt(), nextInt()
var t, a []int
for i := 0; i < n; i++ {
t = append(t, nextInt())
a = append(a, nextInt())
}
ans := solve(n, c, t, a)
PrintVertically(ans)
}
func nextInt() int {
sc.Scan()
i, _ := strconv.Atoi(sc.Text())
return i
}
func PrintInt(x int) {
defer out.Flush()
fmt.Fprintln(out, x)
}
func PrintVertically(x []int) {
defer out.Flush()
for _, v := range x {
fmt.Fprintln(out, v)
}
}
Submission Info
Submission Time |
|
Task |
E - Many Operations |
User |
hima398 |
Language |
Go (1.14.1) |
Score |
500 |
Code Size |
2088 Byte |
Status |
AC |
Exec Time |
166 ms |
Memory |
18508 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
All |
hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt |
Case Name |
Status |
Exec Time |
Memory |
hand_01.txt |
AC |
5 ms |
1804 KiB |
random_01.txt |
AC |
160 ms |
16276 KiB |
random_02.txt |
AC |
86 ms |
9552 KiB |
random_03.txt |
AC |
154 ms |
17596 KiB |
random_04.txt |
AC |
78 ms |
8916 KiB |
random_05.txt |
AC |
163 ms |
17784 KiB |
random_06.txt |
AC |
67 ms |
7036 KiB |
random_07.txt |
AC |
162 ms |
17716 KiB |
random_08.txt |
AC |
10 ms |
2468 KiB |
random_09.txt |
AC |
163 ms |
18508 KiB |
random_10.txt |
AC |
136 ms |
15348 KiB |
random_11.txt |
AC |
157 ms |
15488 KiB |
random_12.txt |
AC |
110 ms |
11268 KiB |
random_13.txt |
AC |
161 ms |
17780 KiB |
random_14.txt |
AC |
152 ms |
15348 KiB |
random_15.txt |
AC |
156 ms |
16620 KiB |
random_16.txt |
AC |
164 ms |
17636 KiB |
random_17.txt |
AC |
113 ms |
11408 KiB |
random_18.txt |
AC |
166 ms |
17888 KiB |
random_19.txt |
AC |
73 ms |
8552 KiB |
random_20.txt |
AC |
161 ms |
16384 KiB |
sample_01.txt |
AC |
5 ms |
1808 KiB |
sample_02.txt |
AC |
2 ms |
1816 KiB |