이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
using namespace std;
ll count_swaps(vector<int> s){
int n = s.size() / 2;
ll ans = 0;
int pref[2*n];
int encZ=0;
int l,r;
for(int i = 0 ; i < 2*n ; i++){
if(s[i]<0){
l=i;
break;
}
}
for(int i = 0 ;i < 2*n ; i++){
if(s[i]>0){
r=i;
break;
}
}
for(int i = 0 ; i < 2*n ; i++){
if(s[i]==0){
encZ++;
pref[i]=encZ;
continue;
}
if(s[i] < 0){
ans += r-l-1-(pref[r]-pref[max(l-1,0)]);
s[r]=0;
for(int j = l+1 ; j < 2*n ; j++){
if(s[j] <0){
l=j;
break;
}
}
for(int j = r ; j < 2*n ; j++){
if(s[j]>0){
r=j;
break;
}
}
}
else{
ans += l-r-(pref[l]-pref[max(r-1,0)]);
s[l] = 0;
for(int j = r+1 ; j < 2*n ; j++){
if(s[j] >0){
r=j;
break;
}
}
for(int j = l+1 ; j < 2*n ; j++){
if(s[j]<0){
l=j;
break;
}
}
}
}
return ans;
}
// int main(){
// int p=1,n=-1;
// cout << count_swaps({p,n,n,n,n,p,p,n,p,p,p,n,n,p}) << endl;
// }
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:36:12: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
36 | for(int j = l+1 ; j < 2*n ; j++){
| ^
# | 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... |