Submission #1016341

#TimeUsernameProblemLanguageResultExecution timeMemory
1016341UnforgettableplMechanical Doll (IOI18_doll)C++17
53 / 100
94 ms16716 KiB
#include <bits/stdc++.h> using namespace std; enum { EXIT = 2000000, }; void answer(vector<int> C, vector<int> X, vector<int> Y); void create_circuit(int M, vector<int> A) { int N = A.size(); vector<int> C(M + 1); vector<int> X(4*N),Y(4*N); vector<vector<int>> nextoccurences(M+1); A.emplace_back(EXIT); for(int i=0;i<N;i++)nextoccurences[A[i]].emplace_back(A[i+1]); int S = 0; for(int i=1;i<=M;i++){ if(nextoccurences[i].empty())continue; int siz = 1; while(nextoccurences[i].size()>siz)siz<<=1; if(nextoccurences[i].size()==siz)continue; while(nextoccurences[i].size()<siz-1)nextoccurences[i].emplace_back(-i); nextoccurences[i].emplace_back(0); } int extraneeded = 0; int head = -1; pair<bool,int> exitnode; function<void(int,vector<int>)> calc = [&](int x,vector<int> targets){ if(targets.size()==2){ if(targets[0]==EXIT){ exitnode = {false,-x}; } else if(targets[0]==0){ X[x] = extraneeded; extraneeded = head; } else if(targets[0]<0){ X[x] = head; } else { X[x] = targets[0]; } if(targets[1]==EXIT){ exitnode = {true,-x}; } else if(targets[1]==0){ Y[x] = extraneeded; extraneeded = head; } else if(targets[1]<0){ Y[x] = head; } else { Y[x] = targets[1]; } } else { vector<int> odds; vector<int> evens; for(int i=0;i<targets.size();i++) if(i&1)odds.emplace_back(targets[i]); else evens.emplace_back(targets[i]); X[x] = -(++S); calc(S,evens); Y[x] = -(++S); calc(S,odds); } }; for(int i=1;i<=M;i++){ if(nextoccurences[i].empty())continue; if(nextoccurences[i].size()==1){ if(nextoccurences[i][0]==EXIT){ exitnode = {false,i}; } else { C[i] = nextoccurences[i][0]; } continue; } head = -(++S); C[i]=head; calc(-head,nextoccurences[i]); } if(exitnode.second>0){ C[exitnode.second]=extraneeded; } else { if(!exitnode.first)X[-exitnode.second]=extraneeded; else Y[-exitnode.second]=extraneeded; } C[0] = A[0]; X.erase(X.begin()); Y.erase(Y.begin()); X.resize(S); Y.resize(S); answer(C, X, Y); }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:21:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         while(nextoccurences[i].size()>siz)siz<<=1;
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
doll.cpp:22:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |         if(nextoccurences[i].size()==siz)continue;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
doll.cpp:23:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |         while(nextoccurences[i].size()<siz-1)nextoccurences[i].emplace_back(-i);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
doll.cpp: In lambda function:
doll.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for(int i=0;i<targets.size();i++)
      |                         ~^~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...