Submission #423736

#TimeUsernameProblemLanguageResultExecution timeMemory
423736tqbfjotldChameleon's Love (JOI20_chameleon)C++14
40 / 100
3 ms456 KiB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

namespace {

int p[505];
int inv[505];
vector<int> adjl[505];

}

void Solve(int N) {

    for (int x = 1; x<=2*N; x++){
        for (int y = x+1; y<=2*N; y++){
            int res = Query({x,y});
            if (res==1){
                adjl[x].push_back(y);
                adjl[y].push_back(x);
            }
        }
    }
    for (int x = 1; x<=2*N; x++){
        if (adjl[x].size()==3){
            int res1 = Query({x,adjl[x][0],adjl[x][1]});
            int res2 = Query({x,adjl[x][1],adjl[x][2]});
            int res3 = Query({x,adjl[x][0],adjl[x][2]});
            if (res1==1){
                p[x] = adjl[x][2];
            }
            else if (res2==1){
                p[x] = adjl[x][0];
            }
            else{
                p[x] = adjl[x][1];
            }
            inv[p[x]] = x;
        }
    }
    for (int x = 1; x<=2*N; x++){
        if (adjl[x].size()<3){
            if (x<adjl[x][0]){
                Answer(x,adjl[x][0]);
            }
        }
        else{
            int other = -1;
            for (auto y : adjl[x]){
                if (y==p[x]) continue;
                if (y==inv[x]) continue;
                other = y;
            }
            if (x<other){
                Answer(x,other);
            }
        }
    }
}

Compilation message (stderr)

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:28:17: warning: unused variable 'res3' [-Wunused-variable]
   28 |             int res3 = Query({x,adjl[x][0],adjl[x][2]});
      |                 ^~~~
#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...