QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#638674 | #9449. New School Term | ucup-team1338# | WA | 415ms | 26740kb | C++14 | 2.8kb | 2024-10-13 16:35:47 | 2024-10-13 16:35:49 |
Judging History
answer
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 1000006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
#define int long long
const ll P = 1e18 + 9;
int n , m;
int A[MAXN] , B[MAXN];
int fa[MAXN] , wf[MAXN] , sz[MAXN][2];
int find( int x ) {
return x == fa[x] ? x : find( fa[x] );
}
int gw( int x ) {
return x == fa[x] ? 0 : wf[x] ^ gw( fa[x] );
}
int gsz( int u ) {
return sz[u][0] + sz[u][1];
}
void connect( int u , int v , int w ) {
int wu = gw( u ) , wv = gw( v ) , fu = find( u ) , fv = find( v );
if( fu == fv ) return;
if( gsz( fu ) > gsz( fv ) ) swap( u , v ) , swap( fu , fv ) , swap( wu , wv );
fa[fu] = fv , wf[fu] = wu ^ wv ^ w;
sz[fv][0] += sz[fu][wu ^ wv ^ w] , sz[fv][1] += sz[fu][wu ^ wv ^ w ^ 1];
}
int qm( int x ) {
return x < P ? x : x - P;
}
int dp[MAXN] , W;
void add( int a , int b ) {
if( a > b ) swap( a , b );
b -= a;
W += b;
if( !b ) return;
for( int i = n * 2 ; i >= b ; -- i )
dp[i] = qm( dp[i] + dp[i - b] );
}
void del( int a , int b ) {
if( a > b ) swap( a , b );
b -= a;
W -= b;
if( !b ) return;
for( int i = b ; i <= n * 2 ; ++ i )
dp[i] = qm( dp[i] + P - dp[i - b] );
}
void solve() {
cin >> n >> m;
rep( i , 1 , n * 2 ) A[i] = 1 , B[i] = i;
rep( i , 1 , m ) scanf("%lld%lld",A + i + n + n,B + i + n + n);
dp[0] = 1;
rep( i , 1 , n * 2 ) {
add( 0 , 1 );
fa[i] = i , sz[i][0] = 1 , sz[i][1] = 0 , wf[i] = 0;
}
for( int i = m + n * 2 ; i >= 1 ; -- i ) {
int a = A[i] , b = B[i];
int aa = find( a ) , bb = find( b ) , wa = gw( a ) , wb = gw( b );
if( aa == bb ) continue;
del( sz[aa][0] , sz[aa][1] );
del( sz[bb][0] , sz[bb][1] );
pii na = mp( sz[aa][wa] + sz[bb][wb] , sz[aa][wa ^ 1] + sz[bb][wb ^ 1] );
pii ta = mp( sz[aa][wa] + sz[bb][wb ^ 1] , sz[aa][wa ^ 1] + sz[bb][wb] );
add( ta.fi , ta.se );
if( W % 2 == 0 && dp[W / 2] ) {
connect( a , b , 1 );
continue;
}
del( ta.fi , ta.se );
add( na.fi , na.se );
connect( a , b , 0 );
}
rep( i , 1 , n * 2 ) putchar(gw( i ) + '0'); puts("");
}
signed main() {
// int T;cin >> T;while( T-- ) solve();
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13848kb
input:
2 4 1 3 2 4 1 4 1 2
output:
1010
result:
ok Output is valid. OK
Test #2:
score: 0
Accepted
time: 2ms
memory: 14044kb
input:
3 7 2 5 1 3 4 6 2 6 4 5 2 4 5 6
output:
110010
result:
ok Output is valid. OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 13984kb
input:
1 0
output:
10
result:
ok Output is valid. OK
Test #4:
score: 0
Accepted
time: 0ms
memory: 14104kb
input:
1 1 1 2
output:
10
result:
ok Output is valid. OK
Test #5:
score: 0
Accepted
time: 0ms
memory: 13840kb
input:
2 3 2 4 3 4 1 2
output:
0110
result:
ok Output is valid. OK
Test #6:
score: 0
Accepted
time: 0ms
memory: 13888kb
input:
3 8 4 6 3 5 1 4 2 4 1 6 1 2 3 4 4 5
output:
010101
result:
ok Output is valid. OK
Test #7:
score: 0
Accepted
time: 2ms
memory: 14044kb
input:
4 9 4 7 3 8 1 5 2 7 2 8 6 8 7 8 1 4 1 6
output:
10101001
result:
ok Output is valid. OK
Test #8:
score: 0
Accepted
time: 0ms
memory: 13984kb
input:
5 16 3 6 9 10 2 7 1 10 1 5 2 10 3 5 5 6 3 4 2 5 4 5 3 8 4 7 6 8 1 6 7 10
output:
0010111010
result:
ok Output is valid. OK
Test #9:
score: 0
Accepted
time: 2ms
memory: 14104kb
input:
6 13 4 5 2 9 3 8 4 8 4 11 10 12 3 4 3 9 5 11 2 8 5 10 5 8 1 11
output:
110110001001
result:
ok Output is valid. OK
Test #10:
score: 0
Accepted
time: 0ms
memory: 13964kb
input:
12 153 1 24 16 18 7 14 1 16 20 21 9 14 21 22 4 5 17 24 4 12 5 17 13 24 14 15 12 23 12 16 8 11 14 24 9 16 2 5 6 19 11 17 4 22 4 7 6 16 7 20 8 15 5 24 2 10 10 21 21 24 1 12 11 19 18 21 18 24 12 17 13 22 7 9 13 23 4 9 11 13 15 21 5 7 2 4 15 16 17 19 11 16 11 20 7 8 4 15 13 14 6 18 2 19 9 13 23 24 4 21 ...
output:
111100011001101110000001
result:
ok Output is valid. OK
Test #11:
score: 0
Accepted
time: 3ms
memory: 14032kb
input:
259 33757 472 500 65 336 138 469 307 442 427 458 43 239 17 508 460 466 108 393 79 92 250 483 44 277 17 132 35 57 155 499 184 474 246 272 274 418 457 458 338 372 196 514 31 208 117 187 90 229 153 284 189 355 16 337 146 456 269 271 279 412 305 336 303 441 399 472 85 286 91 97 157 437 137 379 71 360 27...
output:
111000110010111001101110000111000000011111100010101100100010001110101101111110000111000101111100010110101110111100011010101100111010010011101010011010011010011101100111001011110001100111000010101011100110110001001010010010101010010110011001100001010110000100001110101110000010110001010010000110110011...
result:
ok Output is valid. OK
Test #12:
score: 0
Accepted
time: 40ms
memory: 18096kb
input:
811 265557 217 1153 383 1609 165 177 612 1602 1057 1428 37 436 135 1200 368 684 448 722 145 1583 325 1052 246 480 74 148 122 1111 1256 1327 304 1070 1285 1542 802 813 454 1563 265 1193 94 848 432 1156 429 1194 427 1230 1152 1406 1329 1355 702 845 591 1232 877 1288 1257 1549 340 659 1080 1333 910 137...
output:
110111111101000111011111111101011110100101000101001000000001111000101111010100100101110100110101000111110100111100100110111110100101110101111100011110101010011001101010100110010011011111011011110101111111011000001100001101110111111110100010011100011110111111010001011111110110011111100001010011011101...
result:
ok Output is valid. OK
Test #13:
score: 0
Accepted
time: 88ms
memory: 22200kb
input:
1691 323743 1246 2397 1445 2647 2010 2806 2001 2896 802 2258 2679 2976 2203 2875 2445 2698 137 3004 536 1800 2316 2520 594 1517 279 1558 1934 2871 57 1358 357 976 1764 2672 869 2137 1694 2201 491 1906 1177 1414 1304 1377 2454 2653 626 2637 1425 1677 620 876 1326 2085 404 874 626 1565 136 597 2885 31...
output:
111010001000000110110000100100010011101101011001011100101110000011100010001111000001000010100101111010111000111000110011100100110000110001001101110010110111110110110010100101010101000100100010111001011011111110010011000011110101000111011010010110101011011001001110100100110001100101111100111011101010...
result:
ok Output is valid. OK
Test #14:
score: 0
Accepted
time: 173ms
memory: 17980kb
input:
2891 285302 2273 3206 2376 4737 1075 5673 2493 5453 548 1902 603 1376 1948 2985 108 4730 2172 2948 947 1758 762 1558 2813 5701 2287 3502 297 1501 568 4247 4569 5071 832 3005 412 4226 1813 4519 726 3017 1658 3990 1771 3230 1705 2149 765 4782 5420 5652 3089 4727 4362 5054 1578 3729 1111 5740 2234 5691...
output:
001110110111111001100111000010110001001000011010100001010110101011011111011011111000101110011000000001111010101010010001000111101110110100111011001111111000110010101000000110100011111110110001010000001010101000111000111111111010100111001010100001110100011110111111111010100110110001110011110111001110...
result:
ok Output is valid. OK
Test #15:
score: 0
Accepted
time: 415ms
memory: 26384kb
input:
4413 717147 1990 3721 2169 8724 2894 5350 4689 5732 274 3456 3149 5664 463 6517 3482 7460 1820 5440 2995 6364 5476 7590 5989 8692 4286 7015 7520 8630 524 7821 3335 7017 1491 4477 6238 8230 6339 8087 565 8666 6188 6930 4280 7015 4393 8825 3686 6189 3711 6905 888 1997 2488 8544 9 3914 5135 5322 2778 6...
output:
101101100111010000110001100011010100101110101111100111111001010100010110110001010001100100001010011100001001011011100110011000000101000011111100011001101011101100001010111001111101110001011100001011101001101000011100110101011100101110110010100010111111110011011011010101001000000111100101110110001111...
result:
ok Output is valid. OK
Test #16:
score: -100
Wrong Answer
time: 84ms
memory: 26740kb
input:
707 998991 16 83 733 1195 318 945 9 385 764 1338 396 833 408 1331 541 1405 167 1351 572 838 16 334 36 1071 765 873 445 930 48 168 857 1306 1066 1408 270 720 116 698 737 1136 460 1074 585 1195 492 690 1103 1122 698 1239 623 1355 30 140 952 1088 776 1138 71 525 690 1194 357 1062 366 632 46 744 312 520...
output:
000000000000000000000000000010000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000010000000000000000000000000001000000100000000000000000000000000000000000000000000000000000000000100000000000000000000000100001111110101110111111111101011111111101...
result:
wrong answer The size of S must be 2N.