답안 #495979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495979 2021-12-20T08:59:54 Z AlperenT Checker (COCI19_checker) C++17
110 / 110
348 ms 30540 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int t, n, a, b, c, lg2[N];

string str;

vector<pair<int, int>> graph[N];

vector<array<int, 3>> edges;

priority_queue<int, vector<int>, greater<int>> pq;

bool flag1 = true, flag2 = true;

bool check(int nodea, int nodeb, int c){
    vector<pair<int, int>> v, &va = graph[nodea], &vb = graph[nodeb];

    bool flag = false;
    if(vb.size() < va.size()) flag = true, swap(va, vb);

    if(va.size() * (lg2[vb.size()] + 1) < va.size() + vb.size()){;
        for(auto p : va){
            auto it = lower_bound(vb.begin(), vb.end(), pair{p.first, 0});

            if(it != vb.end()){
                pair<int, int> p2 = *it;

                if(p.first == p2.first) v.push_back({p.second, p2.second});
            }
        }
    }
    else{
        int a = 0, b = 0;

        while(a < va.size() && b < vb.size()){
            if(va[a].first == vb[b].first){
                v.push_back({va[a].second, vb[b].second});
                a++, b++;
            }
            else if(va[a].first < vb[b].first) a++;
            else if(vb[b].first < va[a].first) b++;
        }
    }

    if(flag) swap(va, vb);

    for(auto p : v){
        if(p.first != p.second && p.first != c && p.second != c) continue;
        else return false;
    }

    return true;
}

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

    for(int i = 2; i < N; i++) lg2[i] = lg2[i / 2] + 1;

    cin >> t >> n;

    cin >> str;

    str = '$' + str;

    for(int i = 1; i <= n - 1; i++){
        edges.push_back({i, i + 1, str[i] - '0'});
        edges.push_back({i + 1, i, str[i] - '0'});
    }

    edges.push_back({n, 1, str[n] - '0'});
    edges.push_back({1, n, str[n] - '0'});

    for(int i = 1; i <= n - 3; i++){
        cin >> a >> b >> c;

        if(b < a) swap(a, b);

        graph[a].push_back({b, c});
        edges.push_back({b, a, c});
    }

    for(int v = 1; v <= n; v++){
        while(!pq.empty() && pq.top() <= v) pq.pop();

        for(auto e : graph[v]) if(!pq.empty() && e.first > pq.top()) flag1 = false;

        for(auto e : graph[v]) pq.push(e.first);
    }

    if(flag1){
        for(auto e : edges) graph[e[0]].push_back({e[1], e[2]});

        for(int v = 1; v <= n; v++) sort(graph[v].begin(), graph[v].end());

        for(int v = 1; v <= n; v++){
            for(auto e : graph[v]){
                if(!check(v, e.first, e.second)) flag2 = false;
            }
        }
    }

    if(!flag1) cout << "neispravna triangulacija";
    else{
        if(!flag2) cout << "neispravno bojenje";
        else cout << "tocno";
    }
}

Compilation message

checker.cpp: In function 'bool check(int, int, int)':
checker.cpp:39:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         while(a < va.size() && b < vb.size()){
      |               ~~^~~~~~~~~~~
checker.cpp:39:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         while(a < va.size() && b < vb.size()){
      |                                ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 8 ms 5964 KB Output is correct
9 Correct 6 ms 5964 KB Output is correct
10 Correct 4 ms 5960 KB Output is correct
11 Correct 5 ms 5960 KB Output is correct
12 Correct 6 ms 5964 KB Output is correct
13 Correct 6 ms 5964 KB Output is correct
14 Correct 6 ms 5940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 25228 KB Output is correct
2 Correct 295 ms 25204 KB Output is correct
3 Correct 120 ms 20920 KB Output is correct
4 Correct 106 ms 20824 KB Output is correct
5 Correct 129 ms 20872 KB Output is correct
6 Correct 261 ms 27052 KB Output is correct
7 Correct 341 ms 29288 KB Output is correct
8 Correct 116 ms 23024 KB Output is correct
9 Correct 93 ms 22196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 282 ms 25188 KB Output is correct
2 Correct 296 ms 25256 KB Output is correct
3 Correct 301 ms 25172 KB Output is correct
4 Correct 317 ms 25196 KB Output is correct
5 Correct 290 ms 25304 KB Output is correct
6 Correct 279 ms 26460 KB Output is correct
7 Correct 296 ms 29304 KB Output is correct
8 Correct 257 ms 30124 KB Output is correct
9 Correct 348 ms 29276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 8 ms 5964 KB Output is correct
9 Correct 6 ms 5964 KB Output is correct
10 Correct 4 ms 5960 KB Output is correct
11 Correct 5 ms 5960 KB Output is correct
12 Correct 6 ms 5964 KB Output is correct
13 Correct 6 ms 5964 KB Output is correct
14 Correct 6 ms 5940 KB Output is correct
15 Correct 270 ms 25228 KB Output is correct
16 Correct 295 ms 25204 KB Output is correct
17 Correct 120 ms 20920 KB Output is correct
18 Correct 106 ms 20824 KB Output is correct
19 Correct 129 ms 20872 KB Output is correct
20 Correct 261 ms 27052 KB Output is correct
21 Correct 341 ms 29288 KB Output is correct
22 Correct 116 ms 23024 KB Output is correct
23 Correct 93 ms 22196 KB Output is correct
24 Correct 282 ms 25188 KB Output is correct
25 Correct 296 ms 25256 KB Output is correct
26 Correct 301 ms 25172 KB Output is correct
27 Correct 317 ms 25196 KB Output is correct
28 Correct 290 ms 25304 KB Output is correct
29 Correct 279 ms 26460 KB Output is correct
30 Correct 296 ms 29304 KB Output is correct
31 Correct 257 ms 30124 KB Output is correct
32 Correct 348 ms 29276 KB Output is correct
33 Correct 303 ms 28284 KB Output is correct
34 Correct 271 ms 28264 KB Output is correct
35 Correct 118 ms 23080 KB Output is correct
36 Correct 139 ms 22988 KB Output is correct
37 Correct 306 ms 28264 KB Output is correct
38 Correct 321 ms 28336 KB Output is correct
39 Correct 269 ms 28316 KB Output is correct
40 Correct 289 ms 30540 KB Output is correct
41 Correct 296 ms 29368 KB Output is correct
42 Correct 148 ms 23280 KB Output is correct
43 Correct 287 ms 29932 KB Output is correct