QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642180#9449. New School TermBalintR#WA 1ms5680kbC++202.4kb2024-10-15 11:33:252024-10-15 11:33:26

Judging History

你现在查看的是最新测评结果

  • [2024-10-15 11:33:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5680kb
  • [2024-10-15 11:33:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
#define pb push_back
#define fs first
#define sn second
#define ms(a, x) memset(a, x, sizeof(a))
#define ALL(v) begin(v), end(v)
#define SZ(v) ((int) (v).size())
const int INF = 0x3f3f3f3f;
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x){cerr << #x << ' ' << (x) << endl;}
#define dbgArr(arr, n){cerr << #arr; FR(_i, n) cerr << ' ' << (arr)[_i]; cerr << endl;}
template <class T, class U>
ostream& operator<<(ostream &os, pair<T, U> p){return os << "(" << p.fs << ", " << p.sn << ")";}

const int MQ = 1e6 + 5;
const int MN = 1e4 + 5;

int freq[MN];
bitset<MN> dp;

bool check(const vi &vec){
    // dbgArr(vec, SZ(vec));
    ms(freq, 0);
    int sm = 0;
    for(int a : vec) freq[a]++, sm += a;
    assert(!(sm & 1));

    dp.reset();
    dp[0] = 1;
    FR(i, MN){
        int c = freq[i];
        while(c > 1) dp |= dp << c/2, c -= c/2;
        if(c) dp |= dp << 1;
    }
    // dbg(dp[sm]);
    return dp[sm];
}

int n, m;
int dsu[MN*2], dsz[MN*2];
pii reqs[MQ];

int find(int a){
    return dsu[a] < 0 ? a : dsu[a] = find(dsu[a]);
}

void merge(int a, int b){
    assert(dsu[a] < 0 && dsu[b] < 0);
    assert(dsu[a^1] < 0 && dsu[b^1] < 0);
    dsz[a] += dsz[b];
    dsz[a^1] += dsz[b^1];
    dsu[b] = a;
    dsu[b^1] = a^1;
}

void tryMerge(int a, int b){
    a = find(a*2); b = find(b*2);
    if(a == b || (a^1) == b) return;
    // cerr << a << ' ' << b << endl;
    vi vec;
    FR(i, n*2){
        int p = i*2;
        if(dsu[p] < 0){
            if(p == a || p == (a^1) || p == b || p == (b^1)) continue;
            // dbg(p);
            vec.pb(abs(dsz[p] - dsz[p^1]));
        }
    }
    vec.pb(abs(dsz[a] + dsz[b^1] - dsz[a^1] - dsz[b]));

    if(check(vec)) merge(a, b^1);
    else merge(a, b);
}

int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    FR(i, m) cin >> reqs[i].fs >> reqs[i].sn, reqs[i].fs--, reqs[i].sn--;
    ms(dsu, -1);
    FR(i, n*2) dsz[i*2] = 1;

    FORR(i, m-1, 0){
        auto [a, b] = reqs[i];
        tryMerge(a, b);
    }
    FOR(i, 1, n*2) tryMerge(0, i);

    FR(i, n*2) cout << (find(i*2) & 1);
    cout << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

2 4
1 3
2 4
1 4
1 2

output:

0101

result:

ok Output is valid. OK

Test #2:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

3 7
2 5
1 3
4 6
2 6
4 5
2 4
5 6

output:

011010

result:

ok Output is valid. OK

Test #3:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

1 0

output:

01

result:

ok Output is valid. OK

Test #4:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

1 1
1 2

output:

01

result:

ok Output is valid. OK

Test #5:

score: 0
Accepted
time: 0ms
memory: 3672kb

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: 3720kb

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: -100
Wrong Answer
time: 1ms
memory: 5680kb

input:

4 9
4 7
3 8
1 5
2 7
2 8
6 8
7 8
1 4
1 6

output:

00011110

result:

wrong answer The division is not minimized.