답안 #861277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861277 2023-10-15T19:09:44 Z Ahmed57 Cat (info1cup19_cat) C++17
16 / 100
1000 ms 8484 KB
#include <bits/stdc++.h>

using namespace std;
vector<pair<int,int>> con;
bool vis[200001];int arr[200001];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t;cin>>t;
    z:while(t--){
        int n;cin>>n;
        for(int i = 1;i<=n;i++)vis[i] = 0;
        con.clear();
        int pos[n+1];
        for(int i = 1;i<=n;i++){
            cin>>arr[i];pos[arr[i]] = i;
        }
        int g = 0;int lol = 0;
        for(int i = 1;i<=n/2;i++){
            if(arr[i]!=i)g++;
            if(n-arr[i]+1!=arr[n-i+1]){
                cout<<-1<<endl;
                goto z;
            }if(arr[i]>n/2){
                lol++;
            }
        }
        if(lol&1){
            cout<<-1<<endl;
            goto z;
        }
        for(int i = 1;i<=n/2;i++){
            if(!vis[i]){
                int st = i;
                vis[i] = 1;
                int e = arr[i];
                while(vis[e]==0){
                    vis[e] = 1;
                    con.push_back({e,i});
                    e = arr[e];
                }
            }
        }
        cout<<con.size()<<" "<<con.size()<<endl;
        for(auto i:con)cout<<i.first<<" "<<i.second<<endl;
    }
}

Compilation message

cat.cpp: In function 'int main()':
cat.cpp:33:21: warning: unused variable 'st' [-Wunused-variable]
   33 |                 int st = i;
      |                     ^~
cat.cpp:13:13: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
   13 |         int pos[n+1];
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 600 KB Correctly distinguished between possibility and impossibility
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 512 KB Output is correct
2 Correct 60 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 600 KB Correctly distinguished between possibility and impossibility
2 Correct 61 ms 512 KB Output is correct
3 Correct 60 ms 596 KB Output is correct
4 Correct 138 ms 932 KB Correctly distinguished between possibility and impossibility
5 Correct 41 ms 596 KB Correctly distinguished between possibility and impossibility
6 Correct 33 ms 604 KB Correctly distinguished between possibility and impossibility
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 512 KB Output is correct
2 Correct 60 ms 596 KB Output is correct
3 Execution timed out 1062 ms 8484 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 600 KB Correctly distinguished between possibility and impossibility
2 Correct 61 ms 512 KB Output is correct
3 Correct 60 ms 596 KB Output is correct
4 Correct 138 ms 932 KB Correctly distinguished between possibility and impossibility
5 Correct 41 ms 596 KB Correctly distinguished between possibility and impossibility
6 Correct 33 ms 604 KB Correctly distinguished between possibility and impossibility
7 Execution timed out 1062 ms 8484 KB Time limit exceeded
8 Halted 0 ms 0 KB -