Submission #470098

#TimeUsernameProblemLanguageResultExecution timeMemory
470098dantoh000Cat (info1cup19_cat)C++14
21.25 / 100
369 ms1840 KiB
#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); vector<int> marked(n/2+1,0); for (int i = 1; i <= n; i++){ scanf("%d",&a[i]); } bool can = true; int sw = 0; int extra = 0; int hmm = 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++; marked[i] = 1; a[i] = n+1-a[i]; if (a[i] == i) hmm++; } } if (sw % 2 != 0) can = false; if (!can){ printf("-1\n"); continue; } int ans = 0; for (int i = 1; i <= n/2; i++){ //printf("%d ",a[i]); if (vis[i] == 0){ int ct = 0; vis[i] = 1; ct += marked[i]; int len = 1; int cur = a[i]; while (cur != i){ ct += marked[cur]; len++; vis[cur] = 1; cur = a[cur]; } //printf("ct = %d len = %d\n",ct,len); if (ct % 2 == 0){ ans += len-1; } else{ if (len == 1 && ct == 1) continue; ans += len; extra ++; } } } ans -= extra/2; ans += hmm/2; if (hmm % 2 == 1) ans++; printf("%d 0\n",ans); } }

Compilation message (stderr)

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:13:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |             scanf("%d",&a[i]);
      |             ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...