답안 #49517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49517 2018-05-30T06:49:23 Z ho94949 낙하산 고리들 (IOI12_rings) C++17
100 / 100
1857 ms 99708 KB
#include<vector>
#include<algorithm>
using namespace std;

const int MAXN = 1010101;

struct UF
{
    int ufd[MAXN];
    int N;
    UF(){}
    UF(int n):N(n)
    {
        for(int i=0; i<n; ++i) ufd[i] = i;
    }
    int Find(int a)
    {
        if(a==ufd[a]) return a;
        return ufd[a] = Find(ufd[a]);
    }
    bool Union(int a, int b)
    {
        a = Find(a); b = Find(b);
        if(a==b) return false;
        ufd[a] = b; return true;
    }
};

struct DAT
{
    UF uf; char deg[MAXN]; int N; int numcyc; int cyclen;  bool ovdeg; 
    DAT(){};
    DAT(int n): N(n), uf(n), numcyc(0), cyclen(0), ovdeg(0){
        for(int i=0; i<N; ++i) deg[i] = 0;
    }
    void Add(int a, int b)
    {
        deg[a]++; deg[b]++; if(deg[a] >= 3 || deg[b] >= 3) ovdeg = 1;
        
        if(!uf.Union(a, b)) 
            if((++numcyc) == 1)
                for(int i=0; i<N; ++i)
                    if(uf.Find(i) == uf.Find(a))
                        ++cyclen;
    }
};
enum PHASE {DEG2, DEG3_1, DEG3_2, DEG3_3, SP1, INF};
PHASE state;

DAT global;


int N, M;
pair<int, int> EList[MAXN];
vector<int> conn[MAXN];
int deg[MAXN], numdeg[5];

vector<int> specials;
vector<DAT> datas;

void Init(int _N) {
    N = _N; M = 0; numdeg[0] = N;
    DAT d(N); global = d;
    state = DEG2;
}
void updatespecials()
{
    for(auto x: specials)
    {
        DAT d(N);
        for(int i=0; i<M; ++i)
        {
            if(EList[i].first == x || EList[i].second == x) continue;
            d.Add(EList[i].first, EList[i].second);
        }
        datas.push_back(d);
    }
}
void makestate(PHASE state)
{
    specials.clear(); datas.clear();
    for(int i=0; i<N; ++i)
    {
        int cnt = (deg[i] >= 3)?1:0;
        for(auto x: conn[i])
            if(deg[x] == 3) ++cnt;
        if(cnt == numdeg[3] + numdeg[4])
            specials.push_back(i);
    }
    updatespecials();
}

void updatestate(PHASE state, int A, int B)
{
    switch(state)
    {
        case DEG2:
            global.Add(A, B);
            break;
        default:
            for(int i=0; i<specials.size(); ++i)
            {
                if(specials[i] == A || specials[i] == B) continue;
                datas[i].Add(A, B);
            }
            break;
    }
}

void Link(int A, int B) {
    if(state == INF) return;
    if(state != DEG2 && datas.size() == 0){state = INF; return;}
    EList[M++] = make_pair(A, B);
    numdeg[min(4, deg[A])]--; numdeg[min(4, deg[B])]--;
    deg[A]++; deg[B]++;
    numdeg[min(4, deg[A])]++; numdeg[min(4, deg[B])]++;
    conn[A].push_back(B);
    conn[B].push_back(A);
    
    
    PHASE newstate = DEG2;
    if(numdeg[4] >= 2){ state = INF; return;}
    else if(numdeg[4] == 1 || numdeg[3] >= 4) newstate = SP1;
    else if(numdeg[3] == 3) newstate = DEG3_3;
    else if(numdeg[3] == 2) newstate = DEG3_2;
    else if(numdeg[3] == 1) newstate = DEG3_1;
    else newstate = DEG2;
    if(state != newstate)
    {
        state = newstate;
        makestate(state);
    }
    else updatestate(state, A, B);
}
//#include<cstdio>
int CountCritical() {
    //if(state == DEG2) puts("DEG2");
    //printf(">%d %d\n", state, (int)datas.size());
    int ans = 0;
    switch(state)
    {
    case DEG2:
        switch(global.numcyc)
        {
            case 0: return N;
            case 1: return global.cyclen;
            default: return 0;
        }
    case INF:
        return 0;
    default:
        for(const auto& x: datas)
            if(x.numcyc==0 && !x.ovdeg ) ++ans;
        return ans;
    }
}







Compilation message

rings.cpp: In constructor 'DAT::DAT(int)':
rings.cpp:31:32: warning: 'DAT::N' will be initialized after [-Wreorder]
     UF uf; char deg[MAXN]; int N; int numcyc; int cyclen;  bool ovdeg; 
                                ^
rings.cpp:31:8: warning:   'UF DAT::uf' [-Wreorder]
     UF uf; char deg[MAXN]; int N; int numcyc; int cyclen;  bool ovdeg; 
        ^~
rings.cpp:33:5: warning:   when initialized here [-Wreorder]
     DAT(int n): N(n), uf(n), numcyc(0), cyclen(0), ovdeg(0){
     ^~~
rings.cpp: In function 'void updatestate(PHASE, int, int)':
rings.cpp:101:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i=0; i<specials.size(); ++i)
                          ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 29048 KB Output is correct
2 Correct 56 ms 53920 KB Output is correct
3 Correct 54 ms 53920 KB Output is correct
4 Correct 27 ms 53920 KB Output is correct
5 Correct 29 ms 53920 KB Output is correct
6 Correct 31 ms 53920 KB Output is correct
7 Correct 52 ms 53920 KB Output is correct
8 Correct 36 ms 53920 KB Output is correct
9 Correct 58 ms 54072 KB Output is correct
10 Correct 55 ms 54088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 54228 KB Output is correct
2 Correct 1208 ms 87352 KB Output is correct
3 Correct 386 ms 87352 KB Output is correct
4 Correct 1467 ms 87352 KB Output is correct
5 Correct 1467 ms 87352 KB Output is correct
6 Correct 1394 ms 87352 KB Output is correct
7 Correct 362 ms 87352 KB Output is correct
8 Correct 1696 ms 93840 KB Output is correct
9 Correct 1857 ms 99708 KB Output is correct
10 Correct 1022 ms 99708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 29048 KB Output is correct
2 Correct 56 ms 53920 KB Output is correct
3 Correct 54 ms 53920 KB Output is correct
4 Correct 27 ms 53920 KB Output is correct
5 Correct 29 ms 53920 KB Output is correct
6 Correct 31 ms 53920 KB Output is correct
7 Correct 52 ms 53920 KB Output is correct
8 Correct 36 ms 53920 KB Output is correct
9 Correct 58 ms 54072 KB Output is correct
10 Correct 55 ms 54088 KB Output is correct
11 Correct 59 ms 99708 KB Output is correct
12 Correct 64 ms 99708 KB Output is correct
13 Correct 63 ms 99708 KB Output is correct
14 Correct 57 ms 99708 KB Output is correct
15 Correct 56 ms 99708 KB Output is correct
16 Correct 33 ms 99708 KB Output is correct
17 Correct 57 ms 99708 KB Output is correct
18 Correct 57 ms 99708 KB Output is correct
19 Correct 33 ms 99708 KB Output is correct
20 Correct 60 ms 99708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 29048 KB Output is correct
2 Correct 56 ms 53920 KB Output is correct
3 Correct 54 ms 53920 KB Output is correct
4 Correct 27 ms 53920 KB Output is correct
5 Correct 29 ms 53920 KB Output is correct
6 Correct 31 ms 53920 KB Output is correct
7 Correct 52 ms 53920 KB Output is correct
8 Correct 36 ms 53920 KB Output is correct
9 Correct 58 ms 54072 KB Output is correct
10 Correct 55 ms 54088 KB Output is correct
11 Correct 59 ms 99708 KB Output is correct
12 Correct 64 ms 99708 KB Output is correct
13 Correct 63 ms 99708 KB Output is correct
14 Correct 57 ms 99708 KB Output is correct
15 Correct 56 ms 99708 KB Output is correct
16 Correct 33 ms 99708 KB Output is correct
17 Correct 57 ms 99708 KB Output is correct
18 Correct 57 ms 99708 KB Output is correct
19 Correct 33 ms 99708 KB Output is correct
20 Correct 60 ms 99708 KB Output is correct
21 Correct 49 ms 99708 KB Output is correct
22 Correct 66 ms 99708 KB Output is correct
23 Correct 75 ms 99708 KB Output is correct
24 Correct 97 ms 99708 KB Output is correct
25 Correct 67 ms 99708 KB Output is correct
26 Correct 105 ms 99708 KB Output is correct
27 Correct 82 ms 99708 KB Output is correct
28 Correct 89 ms 99708 KB Output is correct
29 Correct 80 ms 99708 KB Output is correct
30 Correct 94 ms 99708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 29048 KB Output is correct
2 Correct 56 ms 53920 KB Output is correct
3 Correct 54 ms 53920 KB Output is correct
4 Correct 27 ms 53920 KB Output is correct
5 Correct 29 ms 53920 KB Output is correct
6 Correct 31 ms 53920 KB Output is correct
7 Correct 52 ms 53920 KB Output is correct
8 Correct 36 ms 53920 KB Output is correct
9 Correct 58 ms 54072 KB Output is correct
10 Correct 55 ms 54088 KB Output is correct
11 Correct 507 ms 54228 KB Output is correct
12 Correct 1208 ms 87352 KB Output is correct
13 Correct 386 ms 87352 KB Output is correct
14 Correct 1467 ms 87352 KB Output is correct
15 Correct 1467 ms 87352 KB Output is correct
16 Correct 1394 ms 87352 KB Output is correct
17 Correct 362 ms 87352 KB Output is correct
18 Correct 1696 ms 93840 KB Output is correct
19 Correct 1857 ms 99708 KB Output is correct
20 Correct 1022 ms 99708 KB Output is correct
21 Correct 59 ms 99708 KB Output is correct
22 Correct 64 ms 99708 KB Output is correct
23 Correct 63 ms 99708 KB Output is correct
24 Correct 57 ms 99708 KB Output is correct
25 Correct 56 ms 99708 KB Output is correct
26 Correct 33 ms 99708 KB Output is correct
27 Correct 57 ms 99708 KB Output is correct
28 Correct 57 ms 99708 KB Output is correct
29 Correct 33 ms 99708 KB Output is correct
30 Correct 60 ms 99708 KB Output is correct
31 Correct 49 ms 99708 KB Output is correct
32 Correct 66 ms 99708 KB Output is correct
33 Correct 75 ms 99708 KB Output is correct
34 Correct 97 ms 99708 KB Output is correct
35 Correct 67 ms 99708 KB Output is correct
36 Correct 105 ms 99708 KB Output is correct
37 Correct 82 ms 99708 KB Output is correct
38 Correct 89 ms 99708 KB Output is correct
39 Correct 80 ms 99708 KB Output is correct
40 Correct 94 ms 99708 KB Output is correct
41 Correct 283 ms 99708 KB Output is correct
42 Correct 771 ms 99708 KB Output is correct
43 Correct 360 ms 99708 KB Output is correct
44 Correct 369 ms 99708 KB Output is correct
45 Correct 676 ms 99708 KB Output is correct
46 Correct 881 ms 99708 KB Output is correct
47 Correct 1190 ms 99708 KB Output is correct
48 Correct 354 ms 99708 KB Output is correct
49 Correct 886 ms 99708 KB Output is correct
50 Correct 1036 ms 99708 KB Output is correct
51 Correct 385 ms 99708 KB Output is correct
52 Correct 355 ms 99708 KB Output is correct
53 Correct 308 ms 99708 KB Output is correct
54 Correct 1441 ms 99708 KB Output is correct
55 Correct 1324 ms 99708 KB Output is correct