Submission #672810

# Submission time Handle Problem Language Result Execution time Memory
672810 2022-12-18T09:13:28 Z jamezzz Sorting (IOI15_sorting) C++17
100 / 100
302 ms 25232 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

#define maxn 200005

int a[maxn],pos[maxn],plate[maxn];

int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
    int lo=0,hi=M,mid,res=0;
    while(lo<=hi){
		mid=(lo+hi)>>1;
		//printf("mid: %d\n",mid);
		for(int i=0;i<N;++i)plate[i]=i,a[i]=S[i];
		for(int i=mid-1;i>=0;--i)swap(plate[X[i]],plate[Y[i]]);
		for(int i=0;i<N;++i)pos[plate[i]]=i;
		//printf("pos: ");for(int i=0;i<N;++i)printf("%d ",pos[i]);printf("\n");
		//printf("plate: ");for(int i=0;i<N;++i)printf("%d ",plate[i]);printf("\n");
		vector<pair<int,int>> v;
		for(int i=0;i<N;++i){
			while(plate[i]!=a[i]){
				v.push_back({plate[i],a[i]});
				//printf("swap: %d %d\n",a[i],plate[i]);
				swap(a[i],a[pos[a[i]]]);
			}
		}
		if(v.size()<=mid){
			for(int i=0;i<v.size();++i){
				int a=plate[X[i]],b=plate[Y[i]];
				swap(pos[a],pos[b]);
				swap(plate[X[i]],plate[Y[i]]);
				auto[x,y]=v[i];
				P[i]=pos[x],Q[i]=pos[y];
				//printf("plate: ");for(int i=0;i<N;++i)printf("%d ",plate[i]);printf("\n");
				//printf("pos: ");for(int i=0;i<N;++i)printf("%d ",pos[i]);printf("\n");
			}
			for(int i=v.size();i<M;++i)P[i]=Q[i]=0;
			hi=mid-1;
			res=mid;
		}
		else lo=mid+1;
	}
	return res;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:27:14: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |   if(v.size()<=mid){
      |      ~~~~~~~~^~~~~
sorting.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    for(int i=0;i<v.size();++i){
      |                ~^~~~~~~~~
sorting.cpp:29:9: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   29 |     int a=plate[X[i]],b=plate[Y[i]];
      |         ^
sorting.cpp:7:5: note: shadowed declaration is here
    7 | int a[maxn],pos[maxn],plate[maxn];
      |     ^
sorting.cpp:37:20: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   37 |    for(int i=v.size();i<M;++i)P[i]=Q[i]=0;
      |              ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 1 ms 576 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 1 ms 572 KB Output is correct
25 Correct 1 ms 576 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 516 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
12 Correct 2 ms 448 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 516 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
12 Correct 2 ms 448 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 225 ms 22484 KB Output is correct
16 Correct 245 ms 22964 KB Output is correct
17 Correct 273 ms 24108 KB Output is correct
18 Correct 89 ms 22960 KB Output is correct
19 Correct 172 ms 24296 KB Output is correct
20 Correct 182 ms 24716 KB Output is correct
21 Correct 168 ms 24792 KB Output is correct
22 Correct 224 ms 19460 KB Output is correct
23 Correct 239 ms 24944 KB Output is correct
24 Correct 289 ms 24768 KB Output is correct
25 Correct 289 ms 24308 KB Output is correct
26 Correct 180 ms 23664 KB Output is correct
27 Correct 155 ms 22972 KB Output is correct
28 Correct 260 ms 24656 KB Output is correct
29 Correct 257 ms 24236 KB Output is correct
30 Correct 112 ms 22336 KB Output is correct
31 Correct 270 ms 24736 KB Output is correct
32 Correct 262 ms 24104 KB Output is correct
33 Correct 286 ms 24564 KB Output is correct
34 Correct 257 ms 24504 KB Output is correct
35 Correct 163 ms 23808 KB Output is correct
36 Correct 61 ms 21264 KB Output is correct
37 Correct 284 ms 25232 KB Output is correct
38 Correct 293 ms 24328 KB Output is correct
39 Correct 302 ms 24488 KB Output is correct