# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
711675 | 2023-03-17T11:03:36 Z | guagua0407 | Slagalica (COCI19_slagalica2) | C++17 | 33 ms | 2648 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int main() {_ int n; cin>>n; vector<int> num[9]; vector<int> adj[9]; vector<int> sz(9,0); for(int i=0;i<n;i++){ int a,b; cin>>a>>b; num[a].push_back(b); sz[a]++; } for(int i=1;i<9;i++){ sort(num[i].rbegin(),num[i].rend()); } adj[1].push_back(3); adj[1].push_back(4); adj[1].push_back(8); adj[3].push_back(3); adj[3].push_back(4); adj[3].push_back(8); adj[5].push_back(3); adj[5].push_back(4); adj[5].push_back(8); adj[2].push_back(1); adj[2].push_back(2); adj[2].push_back(7); adj[4].push_back(1); adj[4].push_back(2); adj[4].push_back(7); adj[6].push_back(1); adj[6].push_back(2); adj[6].push_back(7); int cur=(sz[5]>0?5:6); vector<int> ans; ans.push_back(num[cur].back()); num[cur].pop_back(); sz[cur]--; for(int i=0;i<n-2;i++){ //cout<<cur<<'\n'; int mn=1e9+1; int tt; for(auto v:adj[cur]){ //cout<<v<<' '<<sz[v]<<'\n'; if(sz[v]==0) continue; sz[v]--; bool tf=false; for(auto u:adj[v]){ if(i!=n-3 and (u==7 or u==8)) continue; if(sz[u]>0){ tf=true; break; } } sz[v]++; if(tf){ if(num[v].back()<mn){ mn=num[v].back(); tt=v; } } } if(mn==1e9+1){ assert(1==0); cout<<-1; return 0; } sz[tt]--; ans.push_back(num[tt].back()); num[tt].pop_back(); cur=tt; } int target=(sz[7]>0?7:8); bool tf=false; for(auto v:adj[cur]){ if(v==target){ tf=true; break; } } if(!tf){ cout<<-1; return 0; } ans.push_back(num[target].back()); for(auto v:ans){ cout<<v<<' '; } return 0; } //maybe its multiset not set
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Runtime error | 1 ms | 468 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 468 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 2264 KB | Output is correct |
2 | Runtime error | 23 ms | 2384 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 2064 KB | Output is correct |
2 | Runtime error | 22 ms | 2472 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 23 ms | 2092 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 20 ms | 1848 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 21 ms | 1920 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 2000 KB | Output is correct |
2 | Runtime error | 22 ms | 1928 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 23 ms | 2616 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 24 ms | 2648 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 23 ms | 2340 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 28 ms | 2584 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 25 ms | 2508 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 21 ms | 2464 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |