답안 #228247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228247 2020-04-30T09:27:57 Z VEGAnn Teoretičar (COCI18_teoreticar) C++14
26 / 130
947 ms 89756 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;
int col[M], l, r, mrk[2][N][N], m, ans = oo, nm[M], x[M], y[M], tt = 0, X, deg[2][N];

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

void potential(){
    int cur = 0;

    tt++;

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

        for (int c = 0; ; c++)
            if (mrk[0][x[i]][c] < tt && mrk[1][y[i]][c] < tt){
                col[i] = c;
                cur = max(cur, c);

                if (cur > X) {
                    shuffle(nm, nm + m, rnd);
                    return;
                }

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

    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 (;;)
        potential();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 512 KB too many colors
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 20480 KB too many colors
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 11136 KB Output is correct
2 Correct 11 ms 8576 KB Output is correct
3 Correct 23 ms 25856 KB Output is correct
4 Correct 9 ms 5376 KB Output is correct
5 Correct 6 ms 2048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 103 ms 8896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 122 ms 12408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 24780 KB Output is correct
2 Runtime error 121 ms 15096 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 947 ms 89756 KB Output is correct
2 Runtime error 124 ms 15096 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 656 ms 89720 KB Output is correct
2 Runtime error 129 ms 15224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -