답안 #228261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228261 2020-04-30T10:00:21 Z VEGAnn Teoretičar (COCI18_teoreticar) C++14
39 / 130
12000 ms 15992 KB
#include <bits/stdc++.h>
#define pii pair<int,int>
#define ft first
#define sd second
#define MP make_pair
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 5010;
const int M = 500100;
const int oo = 2e9;
bitset<N> mrk[2][N];
int col[M], l, r, m, ans = oo, nm[M], x[M], y[M], X, deg[2][N];

mt19937 rnd(chrono::system_clock().now().time_since_epoch().count());

void potential(){
    int cur = 0;

    for (int it = 0; it < m; it++){
        int i = nm[it];

        int c = (mrk[0][x[i]] & mrk[1][y[i]])._Find_first();

        col[i] = c;
        cur = max(cur, c);

        if (cur >= X) {
            for (int jt = 0; jt < it; jt++){
                int j = nm[jt];
                mrk[0][x[j]][col[j]] = mrk[1][y[j]][col[j]] = 1;
            }

            shuffle(nm, nm + m, rnd);
            return;
        }

        mrk[0][x[i]][c] = mrk[1][y[i]][c] = 0;
    }

    cout << cur + 1 << '\n';

    for (int i = 0; i < m; i++)
        cout << col[i] + 1 << '\n';

    exit(0);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> l >> r >> m;

    for (int i = 0; i < m; i++){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
        deg[0][x[i]]++;
        deg[1][y[i]]++;
        nm[i] = i;
    }

    int mex = 0;

    for (int i = 0; i < max(l, r); i++) {
        mex = max(mex, deg[0][i]);
        mex = max(mex, deg[1][i]);
    }

    X = 1;

    while (X < mex) X += X;

    for (int i = max(l, r) - 1; i >= 0; i--)
    for (int j = min(max(l, r), X) - 1; j >= 0; j--){
        mrk[0][i][j] = mrk[1][i][j] = 1;
    }

    for (;;)
        potential();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1510 ms 504 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 12021 ms 4224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4224 KB Output is correct
2 Correct 7 ms 1792 KB Output is correct
3 Correct 10 ms 6784 KB Output is correct
4 Correct 7 ms 1280 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 11896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 82 ms 11900 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 100 ms 15352 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 13368 KB Output is correct
2 Runtime error 123 ms 15864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 15992 KB Output is correct
2 Runtime error 117 ms 15736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 208 ms 15612 KB Output is correct
2 Runtime error 116 ms 15608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -