답안 #404949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404949 2021-05-15T11:22:12 Z Andyvanh1 Checker (COCI19_checker) C++14
110 / 110
467 ms 34224 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <math.h>

using namespace std;

#define vt vector
#define INF 0x3f3f3f3f
#define pb push_back
#define FORR1(n) for(int i = 0; i < n; i++)
#define FORR2(i,n) for(int i = 0; i < n; i++)
#define all(u) u.begin(),u.end()

typedef long long ll;
typedef vt<int> vi;
typedef pair<int,int> pii;

struct CTD{
    int size;
    vi par;
    vt<set<int>> tree;
    vi sub;
    void init(vt<set<int>> &adj){
        size = adj.size();
        par.resize(size);
        tree=adj;
        sub.resize(size);
        par[0] = -1;
        build(0,-1);
    }
    void build(int u, int p) {
        int n = dfs(u, p); // find the size of each subtree
        int centroid = find_centroid(u, p, n); // find the centroid
        par[centroid] = p;

        // for each tree resulting from the removal of the centroid
        set<int> ref = tree[centroid];
        for (auto v : ref) {
            tree[centroid].erase(v); // remove the edge to disconnect
            tree[v].erase(centroid); // the component from the tree
            build(v, centroid);
        }
    }



    int dfs(int u, int p) {
        sub[u] = 1;

        for (auto v : tree[u])
            if (v != p) sub[u] += dfs(v, u);

        return sub[u];
    }

    int find_centroid(int node, int p, int n){
        for(auto& e: tree[node]){
            if(e!=p&&sub[e]>n/2){
                return find_centroid(e,node,n);
            }
        }
        return node;
    }


};

struct fwtree{
    int size;
    vi arr;
    void init(int n){
        size = n;
        arr.resize(n+2);
        for(int i = 0; i < n+2; i++){
            arr[i] = 0;
        }
    }

    void update(int i, int x){
        for(; i <= size; i+=i&-i){
            arr[i]+=x;
        }
    }

    int get(int i){
        int ans = 0;
        for(; i > 0; i-=i&-i){
            ans+=arr[i];
        }
        return ans;
    }

    int get(int l, int r){
        return get(r)-get(l-1);
    }

};

struct point{
    long double x, y;

};

bool operator<(point p1, point p2){
    return p2.x>p1.x||(p2.x==p1.x&&p2.y>p1.y);
}
vt<pair<int,int>> adjlist[200005];
vi adj[200005];
void solve(){
   int n;
   cin>>n;
   cin>>n;
   string s;
   cin>>s;
   vi colors(n);
   for(int i = 0; i < n; i++){
       colors[i] = s[i]-'0';
   }
   for(int i = 0; i < n; i++){
       int j1, j2;
       if(i!=n-1){
           j1 = i+1;
       }else{
           j1 = 0;
       }
       if(i!=0){
           j2 = i-1;
       }else{
           j2 = n-1;
       }
       adjlist[i].pb({j2,colors[j2]});
       adjlist[i].pb({j1,colors[i]});

   }
   for(int i = 0; i < n-3; i++){
       int u,v,c;
       cin>>u>>v>>c;u--;v--;
       adjlist[u].pb({v,c});
       adjlist[v].pb({u,c});
       if(u>v)swap(u,v);
       adj[u].pb(v);
   }
   set<int> st;
   bool bol1 = true;
   for(int i = 0; i < n; i++){
       if(st.empty()){
           for(auto& e: adj[i]){
               st.insert(e);
           }
           continue;
       }
       if(*(st.begin())==i){
           st.erase(st.begin());
       }
        sort(all(adj[i]));
       for(int j = adj[i].size()-1;j>=0; j--){
           int e = adj[i][j];
           if((!st.empty())&&e>(*(st.begin()))){

               bol1 = false;
           }else{
               st.insert(e);
           }
       }
   }

if(!bol1){
    cout<<"neispravna triangulacija";
    return;
}










   bool bol = true;
   for(int i = 0; i < n; i++){
       vt<pii> e = adjlist[i];
       sort(all(e));
       if(e.size()==2){
           if(e[0].second==e[1].second){
               bol = false;

               continue;
           }
       }


       for(int j = 0; j < e.size()-1; j++){
           if(e[j].first==(i==0?n-1:i-1)&&e[j+1].first==(i==n-1?0:i+1)){
               continue;
           }
           if(e[j+1].second==e[j].second){
               bol = false;

           }
       }
       if(e[0].second==e[e.size()-1].second){
           if(!(e[0].first==1&&e[e.size()-1].first==n-1||e[0].first==0&&e[e.size()-1].first==n-2))
           bol = false;

       }
   }



   cout<<(bol?"tocno":"neispravno bojenje");

}

int main() {
    solve();
    return 0;
}

Compilation message

checker.cpp: In function 'void solve()':
checker.cpp:198:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  198 |        for(int j = 0; j < e.size()-1; j++){
      |                       ~~^~~~~~~~~~~~
checker.cpp:208:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  208 |            if(!(e[0].first==1&&e[e.size()-1].first==n-1||e[0].first==0&&e[e.size()-1].first==n-2))
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9636 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 6 ms 9680 KB Output is correct
5 Correct 8 ms 9676 KB Output is correct
6 Correct 6 ms 9664 KB Output is correct
7 Correct 6 ms 9676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9636 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 6 ms 9680 KB Output is correct
5 Correct 8 ms 9676 KB Output is correct
6 Correct 6 ms 9664 KB Output is correct
7 Correct 6 ms 9676 KB Output is correct
8 Correct 9 ms 9804 KB Output is correct
9 Correct 9 ms 9784 KB Output is correct
10 Correct 8 ms 9780 KB Output is correct
11 Correct 8 ms 9804 KB Output is correct
12 Correct 10 ms 9852 KB Output is correct
13 Correct 9 ms 9836 KB Output is correct
14 Correct 9 ms 9828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 26340 KB Output is correct
2 Correct 368 ms 26324 KB Output is correct
3 Correct 333 ms 26412 KB Output is correct
4 Correct 350 ms 29372 KB Output is correct
5 Correct 331 ms 29524 KB Output is correct
6 Correct 341 ms 31868 KB Output is correct
7 Correct 406 ms 32412 KB Output is correct
8 Correct 377 ms 34224 KB Output is correct
9 Correct 326 ms 30892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 386 ms 26428 KB Output is correct
2 Correct 397 ms 26428 KB Output is correct
3 Correct 395 ms 26304 KB Output is correct
4 Correct 418 ms 26300 KB Output is correct
5 Correct 408 ms 26336 KB Output is correct
6 Correct 415 ms 30604 KB Output is correct
7 Correct 410 ms 30300 KB Output is correct
8 Correct 367 ms 28796 KB Output is correct
9 Correct 394 ms 29356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9636 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 6 ms 9680 KB Output is correct
5 Correct 8 ms 9676 KB Output is correct
6 Correct 6 ms 9664 KB Output is correct
7 Correct 6 ms 9676 KB Output is correct
8 Correct 9 ms 9804 KB Output is correct
9 Correct 9 ms 9784 KB Output is correct
10 Correct 8 ms 9780 KB Output is correct
11 Correct 8 ms 9804 KB Output is correct
12 Correct 10 ms 9852 KB Output is correct
13 Correct 9 ms 9836 KB Output is correct
14 Correct 9 ms 9828 KB Output is correct
15 Correct 382 ms 26340 KB Output is correct
16 Correct 368 ms 26324 KB Output is correct
17 Correct 333 ms 26412 KB Output is correct
18 Correct 350 ms 29372 KB Output is correct
19 Correct 331 ms 29524 KB Output is correct
20 Correct 341 ms 31868 KB Output is correct
21 Correct 406 ms 32412 KB Output is correct
22 Correct 377 ms 34224 KB Output is correct
23 Correct 326 ms 30892 KB Output is correct
24 Correct 386 ms 26428 KB Output is correct
25 Correct 397 ms 26428 KB Output is correct
26 Correct 395 ms 26304 KB Output is correct
27 Correct 418 ms 26300 KB Output is correct
28 Correct 408 ms 26336 KB Output is correct
29 Correct 415 ms 30604 KB Output is correct
30 Correct 410 ms 30300 KB Output is correct
31 Correct 367 ms 28796 KB Output is correct
32 Correct 394 ms 29356 KB Output is correct
33 Correct 393 ms 29436 KB Output is correct
34 Correct 467 ms 29444 KB Output is correct
35 Correct 348 ms 29368 KB Output is correct
36 Correct 379 ms 29324 KB Output is correct
37 Correct 390 ms 29524 KB Output is correct
38 Correct 396 ms 29420 KB Output is correct
39 Correct 365 ms 29524 KB Output is correct
40 Correct 372 ms 32460 KB Output is correct
41 Correct 378 ms 33792 KB Output is correct
42 Correct 338 ms 33748 KB Output is correct
43 Correct 365 ms 32064 KB Output is correct