제출 #468633

#제출 시각아이디문제언어결과실행 시간메모리
468633PiejanVDCArranging Shoes (IOI19_shoes)C++17
10 / 100
1081 ms3132 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

long long count_swaps(vector<int>v) {
	int fixed = -1, n = v.size();
	long long ans = 0;
	while(fixed < n) {
		int right,pos;
		for(int i = fixed+1 ; i < n ; i++) {
			if(v[i] < 0) {
				right = -v[i],pos=i;
				break;
			}
		}
		for(int i = pos-1 ; i > fixed ; i--) {
			ans++;
			swap(v[i],v[i+1]);
		}
		for(int i = fixed+1 ; i < n ; i++) {
			if(v[i] == right) {
				pos=i;
				break;
			}
		}
		for(int i = pos-1 ; i > fixed+1 ; i--) {
			ans++;
			swap(v[i],v[i+1]);
		}
		fixed+=2;
	}
	return ans;
}
/*
signed main() {
	int n; cin>>n;
	vector<int>v(n);
	for(auto &z : v)
		cin >> z;
	cout << count_swaps(v);
}*/

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:11: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |   for(int i = pos-1 ; i > fixed ; i--) {
      |           ^
shoes.cpp:21:4: warning: 'right' may be used uninitialized in this function [-Wmaybe-uninitialized]
   21 |    if(v[i] == right) {
      |    ^~
#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...