Submission #222382

#TimeUsernameProblemLanguageResultExecution timeMemory
222382tqbfjotldChecker (COCI19_checker)C++14
110 / 110
147 ms16472 KiB
#include <bits/stdc++.h>
using namespace std;

    int n;
vector<pair<pair<int,int>,int> > sides;

int iterate(int pos){
    int a = sides[pos].first.first;
    int b = -sides[pos].first.second;
    if (pos==sides.size()-1){
        return pos;
    }
    if (sides[pos+1].first.first==b){
        return pos;
    }
    if (sides[pos+1].first.first!=a){
        return -1;
    }
    int res = iterate(pos+1);
    if (res==-1) return -1;
    if (-sides[res+1].first.second!=b){
        return -1;
    }
    int res2 = iterate(res+1);
    if (res2==-1){
        return -1;
    }
    return res2;
}

int iterate2(int pos){
    int a = sides[pos].first.first;
    int b = -sides[pos].first.second;
    if (pos==sides.size()-1){
        return pos;
    }
    if (sides[pos+1].first.first==b){
        return pos;
    }
    int res = iterate2(pos+1);
    if (res==-1) return -1;

    int res2 = iterate2(res+1);
    if (res2==-1){
        return -1;
    }
    //printf("triangle of (%d,%d),(%d,%d),(%d,%d)\n",a,b,sides[pos+1].first.first,sides[pos+1].first.second,sides[res+1].first.first,sides[res+1].first.second);
    if (sides[pos].second==sides[pos+1].second) return -1;
    if (sides[pos].second==sides[res+1].second) return -1;
    if (sides[pos+1].second==sides[res+1].second) return -1;
    //printf("sides %d %d %d\n",sides[pos].second,sides[pos+1].second,sides[res+1].second);
    return res2;
}

int main(){
    int subtask;
    scanf("%d",&subtask);
    scanf("%d",&n);
    for (int x = 0; x<n; x++){
        char c;
        scanf(" %c",&c);
        if (x!=n-1){
            sides.push_back({{x+1,-x-2},c-'0'});
        }
        else{
            sides.push_back({{1,-n},c-'0'});
        }
    }
    for (int x = 0; x<n-3; x++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if (b<a) swap(a,b);
        if (a+1==b){
            printf("neispravna triangulacija");
            return 0;
        }

        sides.push_back({{a,-b},c});
    }
    sort(sides.begin(),sides.end());
    for (int x = 1; x<sides.size(); x++){
        if (sides[x].first==sides[x-1].first){
            printf("neispravna triangulacija");
            return 0;
        }
    }
    if (iterate(0)==-1){
        printf("neispravna triangulacija");
        return 0;
    }
    if (iterate2(0)==-1){
        printf("neispravno bojenje");
    }
    else{
        printf("tocno");
    }

}

Compilation message (stderr)

checker.cpp: In function 'int iterate(int)':
checker.cpp:10:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (pos==sides.size()-1){
         ~~~^~~~~~~~~~~~~~~~
checker.cpp: In function 'int iterate2(int)':
checker.cpp:34:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (pos==sides.size()-1){
         ~~~^~~~~~~~~~~~~~~~
checker.cpp:32:9: warning: unused variable 'a' [-Wunused-variable]
     int a = sides[pos].first.first;
         ^
checker.cpp: In function 'int main()':
checker.cpp:81:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x = 1; x<sides.size(); x++){
                     ~^~~~~~~~~~~~~
checker.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&subtask);
     ~~~~~^~~~~~~~~~~~~~~
checker.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
checker.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c",&c);
         ~~~~~^~~~~~~~~~
checker.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...