제출 #1034203

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

#define ll long long

ll count_swaps(vector<int> S){
	int N = S.size();

	deque<int> A(N);

	for(int i = 0; i < N; i++){
		A[i] = S[i];
	}

	ll ans = 0;

	while(A.size() > 0){
		int a = A.front();

		if(a < 0 and A[1] == a + 2*a){
			A.pop_front();
			A.pop_front();
			continue;
		}

		if(a < 0){
			for(int i = 0; i < A.size(); i++){
				if(A[i] == a + 2*a){
					while(i != 1){
						swap(A[i], A[i - 1]);
						i--;
						ans++;
					}
				}
				break;
			}
			A.pop_front();
			A.pop_front();
		}
		else{
			for(int i = 0; i < A.size(); i++){
				if(A[i] == a - 2*a){
					while(i != 0){
						swap(A[i], A[i - 1]);
						i--;
						ans++;
					}
				}
				break;
			}
			A.pop_front();
			A.pop_front();
		}
	}

	return ans;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:28:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    for(int i = 0; i < A.size(); i++){
      |                   ~~^~~~~~~~~~
shoes.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    for(int i = 0; i < A.size(); i++){
      |                   ~~^~~~~~~~~~
shoes.cpp:31:22: warning: iteration 2147483648 invokes undefined behavior [-Waggressive-loop-optimizations]
   31 |       swap(A[i], A[i - 1]);
      |                    ~~^~~
shoes.cpp:30:14: note: within this loop
   30 |      while(i != 1){
      |            ~~^~~~
#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...