Submission #940216

# Submission time Handle Problem Language Result Execution time Memory
940216 2024-03-07T06:42:24 Z 1075508020060209tc Slagalica (COCI19_slagalica2) C++14
40 / 70
54 ms 3260 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int n;
vector<int>e[9];
pair<int,int>ar[9];
int lpl[2];
int rpl[2];
int ed;
vector<int>ans;
int ok(int typ){
if(ans.size()==n-2){return 1;}
int rlft=0;
if(ar[typ].second==ed){return 1;}
for(int i=1;i<=4;i++){
    int sz=e[i].size();
    if(ar[i].first!=ar[typ].first){
        continue;
    }
    if(i==typ){
        sz--;
    }
    if(ar[i].second!=ed){
        rlft+=sz;
    }
}
if(rlft==0){return 0;}
return 1;
}

signed main(){
ar[1]={1,1};
ar[2]={1,0};
ar[3]={0,1};
ar[4]={0,0};
ar[5]={-1,1};
ar[6]={-1,0};
ar[7]={1,-1};
ar[8]={0,-1};
cin>>n;
for(int i=1;i<=n;i++){
    int typ;
    int vl;
    cin>>typ>>vl;


    e[typ].push_back(vl);
}

for(int i=1;i<=8;i++){
    sort(e[i].begin(),e[i].end());
    reverse(e[i].begin(),e[i].end());
}
if(e[5].size()+e[6].size()!=1){
    cout<<-1;return 0;
}
if(e[7].size()+e[8].size()!=1){
    cout<<-1;return 0;
}
if(e[7].size()){
    ed=1;
}else{
    ed=0;
}


int lst;
if(e[5].size()){
    lst=1;
    ans.push_back(e[5][0]);
}else{
    lst=0;
    ans.push_back(e[6][0]);
}

for(int i=2;i<=n-1;i++){

    if(lst==1){
        if(e[3].size()+e[4].size()==0){cout<<-1;return 0;}
        if(!e[4].size()){lst=1;ans.push_back(e[3].back());e[3].pop_back();continue;}
        if(!e[3].size()){lst=0;ans.push_back(e[4].back());e[4].pop_back();continue;}
        if(e[4].back()>e[3].back()&&ok(3)){
            lst=1;ans.push_back(e[3].back());e[3].pop_back();continue;
        }else{
            lst=0;ans.push_back(e[4].back());e[4].pop_back();continue;
        }
    }
        if(e[1].size()+e[2].size()==0){cout<<-1;return 0;}
        if(!e[2].size()){lst=1;ans.push_back(e[1].back());e[1].pop_back();continue;}
        if(!e[1].size()){lst=0;ans.push_back(e[2].back());e[2].pop_back();continue;}
        if(e[2].back()>e[1].back()&&ok(1)){
            lst=1;ans.push_back(e[1].back());e[1].pop_back();continue;
        }else{
            lst=0;ans.push_back(e[2].back());e[2].pop_back();continue;
        }

}










if(e[7].size()){
    ed=1;
    ans.push_back(e[7][0]);
}else{
    ed=0;
    ans.push_back(e[8][0]);
}
if(ed+lst!=1){
    cout<<-1;return 0;
}
if(ans.size()!=n){
    cout<<-1;return 0;
}
for(int i=0;i<ans.size();i++){
    cout<<ans[i]<<" ";
}

}

Compilation message

slagalica.cpp: In function 'long long int ok(long long int)':
slagalica.cpp:14:14: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   14 | if(ans.size()==n-2){return 1;}
      |    ~~~~~~~~~~^~~~~
slagalica.cpp: In function 'int main()':
slagalica.cpp:120:14: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  120 | if(ans.size()!=n){
      |    ~~~~~~~~~~^~~
slagalica.cpp:123:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 | for(int i=0;i<ans.size();i++){
      |             ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2700 KB Output is correct
2 Correct 46 ms 2288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 2532 KB Output is correct
2 Correct 40 ms 2044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 1880 KB Output is correct
2 Correct 46 ms 2624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1736 KB Output is correct
2 Correct 50 ms 2632 KB Output is correct
3 Correct 51 ms 3056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 1632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2496 KB Output is correct
2 Correct 41 ms 1820 KB Output is correct
3 Incorrect 43 ms 2120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 2132 KB Output is correct
2 Correct 45 ms 2756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 2352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 2348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 2992 KB Output is correct
2 Correct 44 ms 3260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 2632 KB Output is correct
2 Correct 40 ms 3228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 2124 KB Output isn't correct
2 Halted 0 ms 0 KB -