제출 #335458

#제출 시각아이디문제언어결과실행 시간메모리
335458MohammadHijazArranging Shoes (IOI19_shoes)C++14
10 / 100
1095 ms3328 KiB
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
long long count_swaps(std::vector<int> s) {
	int x = s.size();
	int last = 0;
	long long ans = 0;
	for (int i = 0; i < x; i++) {
		if (s[i]*-1 > 0) {
			int j = i;
			while(last != j) {
				swap(s[j] , s[j - 1]);
				j--;
				ans++;
			}
            int tar;
		    for (j = last + 1; j < x; j++) {
		    	if (s[j] == s[last]*-1) {
		    		tar = j;
		    		break;
		    	}
		    }
		    while(tar != last + 1) {
		    	swap(s[tar] , s[tar - 1]);
		    	tar--;
		    	ans++;
		    }
		    last += 2;
		}
		
	}
	return ans;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:17: warning: 'tar' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |             int tar;
      |                 ^~~
#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...