Submission #1108074

#TimeUsernameProblemLanguageResultExecution timeMemory
1108074AvianshSorting (IOI15_sorting)C++17
0 / 100
99 ms77692 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; bool check(int n, int s[], int m, int x[], int y[], int p[], int q[]){ int be[n]; iota(be,be+n,0); int ber[m][n]; for(int i = m-1;i>=0;i--){ swap(be[x[i]],be[y[i]]); int temp[n]; for(int i = 0;i<n;i++){ temp[be[i]]=i; } copy(temp,temp+n,ber[i]); } int r = 0; for(int i = 0;i<n;i++){ swap(s[x[i]],s[y[i]]); int ind = find(s,s+n,i)-s; swap(s[ind],s[ber[r+1][i]]); p[r]=ind; q[r]=(ber[r+1][i]); r++; } for(;r<m;r++){ p[r]=0; q[r]=0; swap(s[x[r]],s[y[r]]); } for(int i = 0;i<n;i++){ if(s[i]!=i){ return 0; } } return 1; } int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) { int be[n]; iota(be,be+n,0); int ber[m][n]; for(int i = m-1;i>=0;i--){ swap(be[x[i]],be[y[i]]); int temp[n]; for(int i = 0;i<n;i++){ temp[be[i]]=i; } copy(temp,temp+n,ber[i]); } int r = 0; int cn = 1; for(int i = 0;i<n;i++){ swap(s[x[i]],s[y[i]]); int ind = find(s,s+n,i)-s; if(ber[r+cn][i]==ind){ cn++; continue; } swap(s[ind],s[ber[r+cn][i]]); p[r]=ind; q[r]=(ber[r+cn][i]); r++; } for(;r<m;r++){ p[r]=0; q[r]=0; swap(s[x[r]],s[y[r]]); } for(int i = 0;i<n;i++){ assert(s[i]==i); } return r; }

Compilation message (stderr)

sorting.cpp: In function 'bool check(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:13:17: warning: declaration of 'i' shadows a previous local [-Wshadow]
   13 |         for(int i = 0;i<n;i++){
      |                 ^
sorting.cpp:10:13: note: shadowed declaration is here
   10 |     for(int i = m-1;i>=0;i--){
      |             ^
sorting.cpp:21:32: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   21 |         int ind = find(s,s+n,i)-s;
      |                   ~~~~~~~~~~~~~^~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:47:17: warning: declaration of 'i' shadows a previous local [-Wshadow]
   47 |         for(int i = 0;i<n;i++){
      |                 ^
sorting.cpp:44:13: note: shadowed declaration is here
   44 |     for(int i = m-1;i>=0;i--){
      |             ^
sorting.cpp:56:32: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   56 |         int ind = find(s,s+n,i)-s;
      |                   ~~~~~~~~~~~~~^~
#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...