답안 #1080100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080100 2024-08-29T07:06:09 Z Trumling 정렬하기 (IOI15_sorting) C++14
16 / 100
23 ms 28100 KB
    #include "sorting.h"
    #include<bits/stdc++.h>
    using namespace std;
     
    #define F first
    #define S second
    #define pb push_back
    #define all(x) x.begin(),x.end()
    #define INF 9999999999999999
    typedef long long ll;
     
    int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) 
	{
    	ll pos[N];
        for(int i=0;i<N;i++)
			pos[S[i]]=i;
		
    		
		
    	// for(int i=0;i<N;i++)
		// 	cout<<pos[i]<<' ';

		// 	cout<<'\n';
		vector<pair<ll,ll>>v;
		ll n=N;
		ll idx=0;

		if(S[0]!=0 && S[1]!=0)
		{
		swap(S[0],S[1]);
		if(S[0]!=1)
		{
		v.pb({0,pos[0]});
		swap(S[0],S[pos[0]]);
		}
		else
		{
		v.pb({1,pos[0]});
		swap(S[1],S[pos[0]]);
		}
		
		}

		if(S[0]!=1 && S[1]!=1)
		{
		swap(S[0],S[1]);
		
		if(S[0]!=0)
		{
		v.pb({0,pos[1]});
		swap(S[0],S[pos[1]]);
		}
		else
		{
		v.pb({1,pos[1]});
		swap(S[1],S[pos[1]]);
		}
		}

	
		idx=v.size()%2;
		if(S[0]>S[1])
			idx=1-idx;

    	for(int i=2;i<n;i++)
			for(int j=2;j<n-1;j++)
			{
				if(S[j]>S[j+1])
					{
						v.pb({j,j+1});
						swap(S[j],S[j+1]);
						swap(S[0],S[1]);
					}
			}
		
		if(v.size()%2 != idx)
			v.pb({1,1});
			

					
							
					
			
		for(int i=0;i<v.size();i++)
			{
				P[i]=v[i].F;
				Q[i]=v[i].S;
			}
		// for(int i=0;i<N;i++)
		//   	cout<<S[i]<<' ';

     
    	return v.size();
    }

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:76:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   76 |   if(v.size()%2 != idx)
      |      ~~~~~~~~~~~^~~~~~
sorting.cpp:84:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for(int i=0;i<v.size();i++)
      |               ~^~~~~~~~~
sorting.cpp:5:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    5 |     #define F first
sorting.cpp:86:15: note: in expansion of macro 'F'
   86 |     P[i]=v[i].F;
      |               ^
sorting.cpp:6:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    6 |     #define S second
sorting.cpp:87:15: note: in expansion of macro 'S'
   87 |     Q[i]=v[i].S;
      |               ^
sorting.cpp:93:19: warning: conversion from 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   93 |      return v.size();
      |             ~~~~~~^~
sorting.cpp:12:43: warning: unused parameter 'M' [-Wunused-parameter]
   12 |     int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
      |                                       ~~~~^
sorting.cpp:12:50: warning: unused parameter 'X' [-Wunused-parameter]
   12 |     int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
      |                                              ~~~~^~~
sorting.cpp:12:59: warning: unused parameter 'Y' [-Wunused-parameter]
   12 |     int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
      |                                                       ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Integer 1 violates the range [0, 0]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Integer 1 violates the range [0, 0]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Integer 1 violates the range [0, 0]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 28100 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 28100 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -