Submission #711657

# Submission time Handle Problem Language Result Execution time Memory
711657 2023-03-17T10:47:56 Z pcc Slagalica (COCI19_slagalica2) C++14
15 / 70
31 ms 2244 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fs first
#define sc second
vector<int> v[9];
pii dif[] = {{0,0},{1,1},{1,-1},{-1,1},{-1,-1},{0,1},{0,-1},{1,0},{-1,0}};
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int total = 0;
    int cnt = 0;
    for(int i = 0;i<n;i++){
        int a,b;
        cin>>a>>b;
        total += dif[a].fs+dif[a].sc;
        v[a].push_back(b);
    }
    if(total != 0||v[5].size()+v[6].size() != 1||v[7].size()+v[8].size() != 1){
        cout<<-1;
        return 0;
    }
    for(auto &i:v)sort(i.rbegin(),i.rend());
    vector<int> ans;
    int now = 0;
    if(v[5].empty()){
        ans.push_back(v[6][0]);
        now = dif[6].sc;
    }
    else{
        ans.push_back(v[5].back());
        now = dif[5].sc;
    } 
    pii lcnt = {0,0};
    for(int i = 1;i<=4;i++){
        lcnt.fs += v[i].size()*(dif[i].fs>0);
        lcnt.sc += v[i].size()*(dif[i].fs<0);
    }
    for(int i = 1;i<n-1;i++){
        pii tmp = {1e9+10,1e9+10};
        for(int j = 1;j<=4;j++){
            if(i != n-2&&dif[j].sc == -1)if(lcnt.fs-(dif[j].fs == 1)== 0)continue;
            // cout<<j<<endl;
            if(i != n-2&&dif[j].sc == 1)if(lcnt.sc -(dif[j].fs == -1)== 0)continue;
            if(dif[j].fs+now == 0&&!v[j].empty())tmp = min(tmp,make_pair(v[j].back(),j));
        }
        // cout<<i<<":"<<tmp.fs<<' '<<tmp.sc<<' '<<lcnt.fs<<' '<<lcnt.sc<<endl;
        if(tmp.fs > 1e9){
            cout<<-1;
            return 0;
        }
        if(dif[tmp.sc].fs>0)lcnt.fs--;
        else lcnt.sc--;
        ans.push_back(tmp.fs);
        now = dif[tmp.sc].sc;
        v[tmp.sc].pop_back();
    }
    for(auto &i:ans)cout<<i<<' ';
    for(int i = 7;i<=8;i++){
        if(!v[i].empty())cout<<v[i].back();
    }
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:14:9: warning: unused variable 'cnt' [-Wunused-variable]
   14 |     int cnt = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2244 KB Output is correct
2 Correct 14 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2148 KB Output is correct
2 Correct 13 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1040 KB Output is correct
2 Incorrect 22 ms 1484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 984 KB Output is correct
2 Correct 28 ms 2100 KB Output is correct
3 Incorrect 23 ms 1564 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 1184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2192 KB Output is correct
2 Correct 14 ms 972 KB Output is correct
3 Incorrect 21 ms 1552 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1100 KB Output is correct
2 Incorrect 20 ms 1452 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 1676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 1640 KB Output isn't correct
2 Halted 0 ms 0 KB -