QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#844102 | #9968. Just Zeros | ucup-team6329# | TL | 1051ms | 4076kb | C++23 | 2.2kb | 2025-01-05 14:47:42 | 2025-01-05 14:47:43 |
Judging History
answer
#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
int ch = 0, f = 0; x = 0;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
if(f) x = -x;
}
char str[1000005];
int main(){
int h, w, q; read(h), read(w), read(q);
vector<int> f(1 << h, 0), a(w, 0);
for(int i = 0; i < h; i++){
scanf("%s", str);
for(int j = 0; j < w; j++)
if(str[j] - '0') a[j] |= (1 << i);
}
auto calc = [&](int s, int x) -> int {
int cnt0 = 0, cnt1 = 0;
for(int i = 0; i < h; i++){
int c = ((1 << i) & x) ^ ((1 << i) & s);
if(c) cnt1++; else cnt0++;
}
return min(1 + cnt0, cnt1);
};
for(int s = 0; s < (1 << h); s++)
for(int i = 0; i < w; i++)
f[s] += calc(s, a[i]);
int ans = h * w;
for(int s = 0; s < (1 << h); s++){
ans = min(ans, f[s] + __builtin_popcount(s));
// cout << s << " " << f[s] << endl;
}
printf("%d\n", ans);
int row = 0;
while(q--){
scanf("%s", str);
int x, y;
read(x), x--;
if(str[0] == 'R'){
row ^= (1 << x);
for(int s = 0; s < (1 << h); s++)
if((1 << x) & s) swap(f[s], f[s^(1<<x)]);
}
if(str[0] == 'K'){
for(int s = 0; s < (1 << h); s++)
f[s] -= calc(s, a[x] ^ row);
a[x] ^= ((1 << h) - 1);
for(int s = 0; s < (1 << h); s++)
f[s] += calc(s, a[x] ^ row);
}
if(str[0] == 'P'){
read(y), y--;
for(int s = 0; s < (1 << h); s++)
f[s] -= calc(s, a[y] ^ row);
a[y] ^= (1 << x);
for(int s = 0; s < (1 << h); s++)
f[s] += calc(s, a[y] ^ row);
}
ans = h * w;
for(int s = 0; s < (1 << h); s++)
ans = min(ans, f[s] + __builtin_popcount(s));
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
input:
3 4 6 1010 1101 0010 R 2 P 3 1 K 2 P 2 1 K 4 P 3 4
output:
3 2 3 4 3 3 4
result:
ok 7 numbers
Test #2:
score: 0
Accepted
time: 16ms
memory: 3876kb
input:
3 4 100000 0100 0011 0011 R 3 K 1 R 2 K 4 R 3 K 2 P 1 1 K 1 R 1 P 1 4 K 4 K 1 K 4 R 3 K 2 K 2 R 1 K 1 K 4 P 3 2 P 2 1 K 1 R 1 P 3 1 R 3 K 3 P 3 2 P 1 3 K 1 R 1 P 1 1 R 1 P 2 1 R 3 P 3 1 R 2 K 2 R 1 R 1 R 3 P 1 3 R 3 K 3 R 2 R 1 P 3 4 K 1 K 1 P 1 4 R 3 K 1 P 1 2 R 1 K 3 P 2 2 R 1 P 1 1 K 4 R 2 P 3 4 ...
output:
4 4 3 2 3 4 3 2 3 3 4 4 3 4 3 4 3 2 3 2 3 4 3 4 4 5 5 5 4 3 4 4 4 5 4 3 4 4 3 4 3 3 4 5 4 4 5 4 5 4 4 4 4 5 5 4 4 3 4 5 4 3 4 4 5 4 5 4 5 4 4 5 5 4 5 5 4 4 4 3 4 3 2 3 4 4 3 4 4 3 3 4 3 4 4 3 4 3 2 3 2 3 2 3 4 3 2 3 4 4 3 4 5 5 5 5 4 4 4 5 4 4 4 5 5 5 4 3 4 3 4 4 5 4 5 5 5 4 3 4 4 5 4 5 4 5 4 3 4 4 ...
result:
ok 100001 numbers
Test #3:
score: 0
Accepted
time: 25ms
memory: 4076kb
input:
4 3 100000 110 110 010 000 K 2 K 3 K 2 R 4 P 3 3 K 3 K 2 R 4 R 2 R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1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ...
result:
ok 10001 numbers
Test #5:
score: 0
Accepted
time: 9ms
memory: 3796kb
input:
2 2 100000 11 01 K 1 R 1 K 2 R 1 K 1 P 2 2 K 2 R 2 P 2 1 K 2 R 1 R 1 K 1 K 1 R 2 P 1 2 P 2 2 K 2 R 2 K 1 R 2 P 2 1 R 1 K 2 P 1 1 P 1 1 P 1 1 P 2 2 K 1 R 2 P 2 2 P 2 2 P 1 2 P 2 1 R 2 P 2 2 P 2 1 K 2 K 2 P 2 2 P 2 1 R 1 R 1 K 2 K 2 P 2 1 R 1 P 1 2 R 2 P 1 1 R 2 R 1 P 2 1 P 1 1 K 1 K 2 R 1 P 2 1 R 1 K...
output:
2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 2 2 2 2 1 1 1 1 2 1 1 1 1 1 2 1 2 1 2 1 2 2 1 2 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 1 1 2 1 0 1 2 1 2 1 0 1 2 1 2 1 2 2 2 2 2 2 1 2 1 1 1 1 2 1 2 1 1 1 2 2 2 1 1 1 2 2 1 1 1 2 2 1 2 1 1 2 1 2 1 1 1 0 1 1 1 1 2 2 1 2 1 2 2 1 0 1 2 1 2 1 2 1 0 1 0 1 2 1 2 1 0 1 1 1 1 1 1 ...
result:
ok 100001 numbers
Test #6:
score: 0
Accepted
time: 2ms
memory: 3792kb
input:
8 100 100 1011100111011111110000100100100101000100111100011000001000101011001101001011010100110010110100010110 1001100100100101011101110000100001100001010100111011100111101000110011000010010001000010001101000001 0111000100001001100001111000111110100111100000010111100110110010110100000010011011100000...
output:
302 303 304 305 305 304 305 304 303 302 303 302 301 300 301 302 301 302 301 300 299 298 299 300 299 298 299 300 299 300 301 302 302 301 300 299 300 301 302 301 302 303 302 303 302 301 301 300 299 298 297 298 299 298 298 297 298 297 296 295 296 295 294 294 295 296 295 296 297 298 299 299 300 301 302 ...
result:
ok 101 numbers
Test #7:
score: 0
Accepted
time: 1ms
memory: 4000kb
input:
7 100 100 0110101100110100101101011011110110011011111111001001111111111110011000000110010000110001001100000000 1011011110010100111101010001101000100110011111110111000110111110000101000010001001110110101101100101 0010010101110110010111010010000111000101110101111110110010110011100001101001010001101011...
output:
275 275 275 274 273 274 274 275 274 274 273 274 275 275 275 275 275 275 274 273 274 273 272 271 270 269 270 271 272 271 272 271 270 269 270 269 268 267 268 269 270 271 270 269 268 269 270 269 270 271 272 273 274 273 272 271 270 269 268 267 268 267 268 267 268 267 268 269 270 269 268 269 268 267 266 ...
result:
ok 101 numbers
Test #8:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
6 100 100 1010111111000000010001111010011000101111101101010010001010100000000100001011010100001001101110110111 1100110100111000100000011001011111001010000011011011000011010100101110101110110000101001010110001011 0101000000000111000100010011100001001010011001010100110111010111111101001101010011101111...
output:
224 225 226 225 224 224 225 226 225 226 225 226 225 226 225 226 225 226 226 226 226 226 225 226 227 227 226 227 227 228 227 228 229 228 227 228 229 229 228 228 227 228 227 228 227 226 225 224 223 223 223 224 225 225 224 225 225 225 224 225 226 227 226 225 226 226 227 226 226 227 226 226 227 228 229 ...
result:
ok 101 numbers
Test #9:
score: 0
Accepted
time: 11ms
memory: 3856kb
input:
1 100 100000 0011100001111101100101010100101011111101000011001110000100000111100011000010010011011000010011100100 K 90 R 1 R 1 R 1 K 51 K 38 K 47 R 1 R 1 P 1 96 K 56 K 19 K 20 R 1 K 52 P 1 90 P 1 66 P 1 35 R 1 P 1 57 R 1 R 1 P 1 56 R 1 K 29 K 96 R 1 R 1 R 1 R 1 K 40 K 68 P 1 9 P 1 92 P 1 78 R 1 K 30...
output:
46 45 46 45 46 45 44 45 44 45 46 45 46 45 44 45 46 47 46 47 48 47 48 49 48 47 46 47 46 47 46 45 46 47 48 47 48 49 48 49 50 50 49 50 50 50 50 50 49 50 49 50 49 50 50 50 49 50 50 49 48 49 50 49 48 49 48 49 48 47 48 49 48 49 48 47 48 47 46 47 46 45 46 45 46 45 46 47 48 47 46 47 48 47 48 47 46 47 48 49 ...
result:
ok 100001 numbers
Test #10:
score: 0
Accepted
time: 10ms
memory: 4072kb
input:
2 100 100000 1010001101110111101111110111011110011110111110111110111010000110011111101100111001010011110001101110 0110010111101101111010000001001011101100110101000101100001011111100110010110010000110011001011000110 K 50 R 1 K 22 R 2 P 1 19 K 7 R 2 R 1 P 2 95 P 1 1 R 2 K 96 R 1 P 2 34 K 49 R 2 P 2 21...
output:
66 66 65 66 67 67 68 67 68 69 70 71 70 69 69 69 70 69 70 70 69 69 70 71 71 71 71 71 70 70 69 70 71 71 71 70 69 68 68 69 68 69 68 69 69 70 69 69 69 68 68 69 70 70 71 72 71 71 72 71 72 71 70 70 69 68 67 67 68 68 68 69 68 68 67 67 68 69 70 70 69 68 68 69 70 69 70 70 71 72 72 71 71 72 72 71 70 71 71 72 ...
result:
ok 100001 numbers
Test #11:
score: 0
Accepted
time: 1051ms
memory: 3792kb
input:
8 100 100000 1011011101111011000001001110011100111000101001100010001110010100001010010110111001111010111100111100 0111101001110111101001010011011011001010100100111111110111110001010010011111011010010100001110111110 1111110111110010110110111110101111001001000011000000000011111011000100001011011101110...
output:
306 307 306 305 305 306 305 304 303 302 303 303 302 303 302 303 303 304 303 302 301 301 300 301 301 301 302 303 304 303 304 305 306 306 307 306 307 306 307 308 307 306 305 306 305 304 303 303 302 303 303 302 301 302 302 303 302 301 302 301 302 301 302 301 301 302 303 302 303 302 302 303 302 302 302 ...
result:
ok 100001 numbers
Test #12:
score: -100
Time Limit Exceeded
input:
8 100000 100000 01101011010110010101001010111010111001101100100101001101001011000111110101011010010011100000001001011101010011110001111100000001010100011000010001000101100100101010001011111111111101101111110100010010100010100010110101101010000011010100100100100111110001000111100101110100111001100110...
output:
322545 322546 322545 322545 322544 322543 322544 322543 322543 322542 322542 322543 322542 322541 322541 322541 322540 322541 322542 322541 322541 322542 322542 322543 322544 322545 322544 322543 322542 322542 322541 322540 322541 322542 322543 322544 322543 322544 322544 322543 322542 322543 322542...