답안 #470096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470096 2021-09-03T01:28:50 Z dantoh000 Cat (info1cup19_cat) C++14
21.25 / 100
400 ms 16608 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    scanf("%d",&t);
    while (t--){
        int n;
        scanf("%d",&n);
        vector<int> a(n+1,0);
        vector<int> vis(n/2+1,0);
        for (int i = 1; i <= n; i++){
            scanf("%d",&a[i]);
        }
        bool can = true;
        int sw = 0;
        int extra = 0;
        for (int i = 1; i <= n/2; i++){
            if (a[i]+a[n+1-i] != n+1) can = false;
            if (a[i] > n/2){
                sw++;
                a[i] = n+1-a[i];
                if (a[i] == i) extra++;
            }
        }
        if (sw % 2 != 0) can = false;
        if (!can){
            printf("-1\n");
            continue;
        }

        int ans = n/2;
        for (int i = 1; i <= n/2; i++){
            if (vis[i] == 0){
                vis[i] = 1;
                ans--;
                int cur = a[i];
                while (cur != i){
                    vis[cur] = 1;
                    cur = a[cur];
                }
            }
        }

        if (extra % 2 == 1) extra++;
        printf("%d 0\n",ans+extra);


    }


}

Compilation message

cat.cpp: In function 'int main()':
cat.cpp:5:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
cat.cpp:8:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
cat.cpp:12:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |             scanf("%d",&a[i]);
      |             ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 332 KB Correctly distinguished between possibility and impossibility
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 792 KB Correct number of moves
2 Correct 19 ms 716 KB Correct number of moves
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 332 KB Correctly distinguished between possibility and impossibility
2 Correct 19 ms 792 KB Correct number of moves
3 Correct 19 ms 716 KB Correct number of moves
4 Correct 19 ms 780 KB Correctly distinguished between possibility and impossibility
5 Correct 8 ms 512 KB Correctly distinguished between possibility and impossibility
6 Correct 8 ms 332 KB Correctly distinguished between possibility and impossibility
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 792 KB Correct number of moves
2 Correct 19 ms 716 KB Correct number of moves
3 Correct 330 ms 9680 KB Correct number of moves
4 Correct 362 ms 9916 KB Correct number of moves
5 Correct 342 ms 10200 KB Correct number of moves
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 332 KB Correctly distinguished between possibility and impossibility
2 Correct 19 ms 792 KB Correct number of moves
3 Correct 19 ms 716 KB Correct number of moves
4 Correct 19 ms 780 KB Correctly distinguished between possibility and impossibility
5 Correct 8 ms 512 KB Correctly distinguished between possibility and impossibility
6 Correct 8 ms 332 KB Correctly distinguished between possibility and impossibility
7 Correct 330 ms 9680 KB Correct number of moves
8 Correct 362 ms 9916 KB Correct number of moves
9 Correct 342 ms 10200 KB Correct number of moves
10 Correct 400 ms 14052 KB Correctly distinguished between possibility and impossibility
11 Correct 329 ms 14268 KB Correctly distinguished between possibility and impossibility
12 Correct 364 ms 16608 KB Correctly distinguished between possibility and impossibility
13 Correct 382 ms 15940 KB Correctly distinguished between possibility and impossibility
14 Correct 349 ms 16520 KB Correctly distinguished between possibility and impossibility