이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <iostream>
#include <vector>
#include <cstdio>
#define rep(i,a,b) for(int i = a; i<b; i++)
#define per(i,a,b) for(int i = a; i>b; i--)
#define pb push_back
using namespace std;
long long count_swaps(vector<int> s) {
int n = s.size()/2;
bool f = 1;
rep(i,0,n)if(s[i]>0)f = 0;
rep(i,n,n+n)if(s[i]<0)f = 0;
rep(i,0,n)if(s[i]!=(-s[i+n]))f = 0;
if(f){
long long ans = 0;
rep(i,0,n){
ans+= i;
}
return ans;
}
n*=2;
long long ans = 0;
rep(i,0,n){
if(s[i]<0){
int pos;
rep(j,i+1,n){
if((-s[i]) == s[j]){
pos = j;
break;
}
}
per(j,pos, i+1){
swap(s[j], s[j-1]);
ans++;
}
}else{
int pos;
rep(j,i+1,n){
if((-s[i]) == s[j]){
pos = j;
break;
}
}
per(j,pos, i){
swap(s[j], s[j-1]);
ans++;
}
}
//cout << s[i] << endl;
i++;
}
//cout << "ans: " << ans << endl;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:38:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
38 | int pos;
| ^~~
shoes.cpp:26:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
26 | int pos;
| ^~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |