# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
470097 | dantoh000 | Cat (info1cup19_cat) | C++14 | 373 ms | 1952 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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 (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{
ans += len;
if (len != 1) extra++;
}
}
}
ans -= extra/2;
printf("%d 0\n",ans);
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |