제출 #298248

#제출 시각아이디문제언어결과실행 시간메모리
298248RayaabualjamalArranging Shoes (IOI19_shoes)C++14
50 / 100
1095 ms2944 KiB
#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();
	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:26:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |    int pos;
      |        ^~~
shoes.cpp:14:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   14 |    int pos;
      |        ^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...