Submission #312674

#TimeUsernameProblemLanguageResultExecution timeMemory
312674colazcySlagalica (COCI19_slagalica2)C++17
20 / 70
1098 ms11256 KiB
#include <cstdio> #include <cctype> #include <algorithm> #include <vector> using namespace std; const int maxn = 1e5 + 100; inline int read(){ int x = 0;char c = getchar(); while(!isdigit(c))c = getchar(); while(isdigit(c))x = x * 10 + c - '0',c = getchar(); return x; } vector<int> G[16],vec[16]; int n,beg,end,cnt[16],pos[16],nxt[maxn][4]; inline int get(int x){ return pos[x] == vec[x].size() ? 0x7fffffff : vec[x][pos[x]]; } inline void msort(int id){ if(get(nxt[id][1]) < get(nxt[id][0]))swap(nxt[id][1],nxt[id][0]); if(get(nxt[id][2]) < get(nxt[id][0]))swap(nxt[id][2],nxt[id][0]); if(get(nxt[id][2]) < get(nxt[id][1]))swap(nxt[id][1],nxt[id][2]); } inline void add(int u,int v){G[u].push_back(v);} inline void init(){ add(1,3);add(1,4);add(1,8); add(2,1);add(2,2);add(2,7); add(3,3);add(3,4);add(3,8); add(4,1);add(4,2);add(4,7); add(5,3);add(5,4);add(5,8); add(6,1);add(6,2);add(6,7); } int ans[maxn]; inline void dfs(int step,int lst){ if(step == n){ for(int i = 1;i <= n;i++)printf("%d ",ans[i]); puts(""); exit(0); } for(int i = 0;i < G[lst].size();i++)nxt[step][i] = G[lst][i]; msort(step); for(int i = 0;i < G[lst].size();i++){ int v = nxt[step][i]; if(!cnt[v])continue; ans[step + 1] = vec[v][pos[v]]; pos[v]++; cnt[v]--; dfs(step + 1,v); pos[v]--; cnt[v]++; } } int main(){ // freopen("slagalica.in","r",stdin); // freopen("slagalica.out","w",stdout); n = read(); for(int x,i = 1;i <= n;i++){ int a = read(),b = read(); cnt[a]++; vec[a].push_back(b); } for(int i = 1;i <= 8;i++)sort(vec[i].begin(),vec[i].end()); init(); if(cnt[5])ans[1] = vec[5][0],dfs(1,5); else if(cnt[6])ans[1] = vec[6][0],dfs(1,6); puts("-1"); fclose(stdin); fclose(stdout); return 0; }

Compilation message (stderr)

slagalica.cpp: In function 'int get(int)':
slagalica.cpp:16:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  return pos[x] == vec[x].size() ? 0x7fffffff : vec[x][pos[x]];
      |         ~~~~~~~^~~~~~~~~~~~~~~~
slagalica.cpp: In function 'void dfs(int, int)':
slagalica.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0;i < G[lst].size();i++)nxt[step][i] = G[lst][i];
      |                ~~^~~~~~~~~~~~~~~
slagalica.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i = 0;i < G[lst].size();i++){
      |                ~~^~~~~~~~~~~~~~~
slagalica.cpp: In function 'int main()':
slagalica.cpp:56:10: warning: unused variable 'x' [-Wunused-variable]
   56 |  for(int x,i = 1;i <= n;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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...