답안 #711701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711701 2023-03-17T11:24:30 Z minipig Slagalica (COCI19_slagalica2) C++14
20 / 70
33 ms 2184 KB
#include <bits/stdc++.h>
using namespace std;

int block_type[9][2]={{0,0},{1,1},{1,-1},{-1,1},{-1,-1},{0,1},{0,-1},{1,0},{-1,0}};

vector<int> block[9];
int pos[9];
vector<int> ans;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int left_bump=0,left_hole=0,right_bump=0,right_hole=0,start_type,end_type;
    for(int i=0;i<n;i++){
        int type,number;
        cin>>type>>number;
        if(type==5){
            start_type=5;
        }
        else if(type==6){
            start_type=6;
        }
        else if(type==7){
            end_type=7;
        }
        else{
            end_type=8;
        }
        if(block_type[type][0]==1){
            left_bump++;
        }
        else if(block_type[type][0]==-1){
            left_hole++;
        }
        if(block_type[type][1]==1){
            right_bump++;
        }
        else if(block_type[type][1]==-1){
            right_hole++;
        }
        block[type].push_back(number);
    }
    for(int i=1;i<9;i++){
        sort(block[i].begin(),block[i].end());
    }
    if(left_bump!=right_hole||right_bump!=left_hole){
        cout<<"-1\n";
        return 0;
    }
    ans.push_back(block[start_type][0]);
    if(start_type==5){
        right_bump--;
    }
    else{
        right_hole--;
    }
    pos[start_type]++;
    int now=start_type;
    for(int i=0;i<n-1;i++){
        int idx=-1;
        for(int j=1;j<=8;j++){
            if(block_type[now][1]+block_type[j][0]==0&&pos[j]!=block[j].size()){
                if(idx==-1||block[idx][pos[j]]>block[j][pos[j]]){
                    if(!(i!=n-3&&((block_type[j][1]==1&&left_hole==1&&end_type==8)||(block_type[j][1]==-1&&left_bump==1&&end_type==7)))){
                        if((i==n-2)||(j!=7&&j!=8)){
                            idx=j;
                        }
                    }
                }
            }
        }
        if(idx==-1){
            cout<<"-1\n";
            return 0;
        }
        ans.push_back(block[idx][pos[idx]]);
        //cout<<block[idx][pos[idx]]<<" ";
        pos[idx]++;
        if(block_type[idx][0]==1){
            left_bump--;
        }
        else if(block_type[idx][0]==-1){
            left_hole--;
        }
        if(block_type[idx][1]==1){
            right_bump--;
        }
        else if(block_type[idx][1]==-1){
            right_hole--;
        }
        now=idx;
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<" \n"[i==n-1];
    }
    return 0;
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:65:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |             if(block_type[now][1]+block_type[j][0]==0&&pos[j]!=block[j].size()){
      |                                                        ~~~~~~^~~~~~~~~~~~~~~~~
slagalica.cpp:67:130: warning: 'end_type' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |                     if(!(i!=n-3&&((block_type[j][1]==1&&left_hole==1&&end_type==8)||(block_type[j][1]==-1&&left_bump==1&&end_type==7)))){
      |                                                                                                                          ~~~~~~~~^~~
slagalica.cpp:60:19: warning: 'start_type' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     pos[start_type]++;
      |     ~~~~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 1364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 1296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 848 KB Output is correct
2 Incorrect 20 ms 996 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 768 KB Output is correct
2 Correct 28 ms 1796 KB Output is correct
3 Incorrect 21 ms 1056 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1964 KB Output is correct
2 Correct 20 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1832 KB Output is correct
2 Correct 21 ms 848 KB Output is correct
3 Correct 29 ms 2032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 904 KB Output is correct
2 Incorrect 28 ms 1860 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 1476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 1324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 2184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 1976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -