이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define F first
#define S second
#define INF 10000000
#define inf -10000000
#define pb push_back
#define forr(i,p,n) for(int i=p;i<n;i++)
#define mp make_pair
#define upb(a,s) upper_bound(a.begin(),a.end(),s)
#define lwb(a,s) lower_bound(a.begin(),a.end(),s)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
long long count_swaps(std::vector<int> s) {
if(s.size()==2){
if(s[0]<s[1])return 0;
else return 1;
}else{
if(s.size()<1000){
ll c=0;
for(int i=0;i<s.size();i+=2){
if(s[i]<0){
int h=s[i]*-1;
int k=0;
for(int j=i+1;j<s.size();j++){
if(h==s[j]){
k=j;
c+=abs(i+1-j);
break;
}
}
for(int j=k;j>i+1;j--){
swap(s[j],s[j-1]);
}
}
else{
int h=s[i]*-1;
int k=0;
for(int j=i+1;j<s.size();j++){
if(h==s[j]){
k=j;
c+=abs(i-j);
break;
}
}
for(int j=k;j>i;j--){
swap(s[j],s[j-1]);
}
}
/*cout<<c<<endl;
for(int i=0;i<s.size();i++){
cout<<s[i]<<" ";
}
cout<<endl;*/
}
return c;
}
else{
ll n=s.size();
cout<<(n*(n+1))/2<<endl;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<s.size();i+=2){
~^~~~~~~~~
shoes.cpp:32:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i+1;j<s.size();j++){
~^~~~~~~~~
shoes.cpp:46:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i+1;j<s.size();j++){
~^~~~~~~~~
shoes.cpp:70:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |