Submission #314615

# Submission time Handle Problem Language Result Execution time Memory
314615 2020-10-20T13:04:05 Z talant117408 Sorting (IOI15_sorting) C++17
0 / 100
84 ms 632 KB
#include "sorting.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <ll, ll> pii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
inline bool isvowel(char ch){
	ch = tolower(ch);
	return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
 
inline bool isprime(int n){
	if(n < 2 || (n%2 == 0 && n != 2)) return false;
	for(int i = 3; i*i <= n; i++)
		if(n%i == 0) return false;
	return true;
}

const int NN = 6e5+7;
int S[NN], X[NN], Y[NN], tmpS[NN], tmpos[NN];
 
int findSwapPairs(int N, int s[], int M, int x[], int y[], int P[], int Q[]) {
    
    int i, j;
    for(i = 0; i < N; i++){
        S[i] = s[i];
    }
    for(i = 0; i < M; i++){
        X[i] = x[i];
        Y[i] = y[i];
    }
    
    int flag = 0;
    for(i = 0; i < N; i++){
        if(S[i] > S[i+1]){
            flag++;
            break;
        }
    }
    
    if(!flag) return 0;
    
    for(i = 0; i < M; i++){
        vector <pii> sws;
        
        for(j = 0; j < N; j++)
            tmpS[j] = S[j];
        for(j = 0; j <= i; j++)
            swap(tmpS[X[j]], tmpS[Y[j]]);
        for(j = 0; j < N; j++)
            tmpos[tmpS[j]] = j;
        
        for(j = 0; j < N; j++){
            if(tmpos[j] == j) continue;
            sws.pb(mp(tmpS[j], tmpS[tmpos[j]]));
            swap(tmpS[j], tmpS[tmpos[j]]);
            swap(tmpos[tmpS[j]], tmpos[tmpS[tmpos[j]]]);
        }
        if(sz(sws) <= i+1){
            vector <pii> res1;
            
            for(j = 0; j < N; j++){
                tmpS[j] = S[j];
                tmpos[S[j]] = j;
            }
            for(j = 0; j < sz(sws); j++){
                swap(tmpS[X[j]], tmpS[Y[j]]);
                swap(tmpos[tmpS[X[j]]], tmpos[tmpS[Y[j]]]);
                res1.pb(mp(tmpos[sws[j].first], tmpos[sws[j].second]));
                swap(tmpS[tmpos[sws[j].first]], tmpS[tmpos[sws[j].second]]);
                swap(tmpos[tmpS[tmpos[sws[j].first]]], tmpos[tmpS[tmpos[sws[j].second]]]);
            }
            
            while(sz(res1) <= i){
                res1.pb(mp(0, 0));
            }
            for(j = 0; j < sz(res1); j++){
                P[j] = res1[j].first;
                Q[j] = res1[j].second;
            }
            return sz(res1);
        }
    }
    
    return 0;
}


Compilation message

sorting.cpp: In function 'bool isvowel(char)':
sorting.cpp:23:14: warning: conversion from 'int' to 'char' may change value [-Wconversion]
   23 |  ch = tolower(ch);
      |       ~~~~~~~^~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:93:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   93 |                 P[j] = res1[j].first;
sorting.cpp:94:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   94 |                 Q[j] = res1[j].second;
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 632 KB Output is correct
2 Correct 84 ms 632 KB Output is correct
3 Correct 81 ms 632 KB Output is correct
4 Incorrect 1 ms 512 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 632 KB Output is correct
2 Correct 84 ms 632 KB Output is correct
3 Correct 81 ms 632 KB Output is correct
4 Incorrect 1 ms 512 KB Output isn't correct
5 Halted 0 ms 0 KB -