Submission #206035

#TimeUsernameProblemLanguageResultExecution timeMemory
206035SegtreeSorting (IOI15_sorting)C++14
Compilation error
0 ms0 KiB
#include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; typedef long long ll; #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define all(x) x,begin(),x.end() #define rep(i,n) for(int i=0;i<n;i++) #define mod 1000000007 #define mad(a,b) a=(a+b)%mod int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){ int ss[2010]; rep(i,N)ss[i]=S[i]; int R=0; for(;;R++){ swap(S[X[R]],S[Y[R]]); ll cnt=0,s[2010]; rep(i,N)s[i]=S[i]; //cout<<R<<"-";rep(i,N)cout<<"S:"<<s[i]<<endl; rep(i,N){ ll p; rep(j,N)if(i==s[j])p=j; if(i!=p){ cnt++; swap(s[i],s[p]); } } if(cnt<=R+1){ int R=0; for(int i=0;i<N;i++){ ll p; for(int j=0;j<N;j++)if(S[j]==i)p=j; if(i!=p){ P[R]=i,Q[R]=p,R++; swap(S[i],S[p]); } } return R; } } return -1; } int main(){ int n,s[100],m,x[1000],y[1000],p[1000],q[1000]; cin>>n; rep(i,n)cin>>s[i]; cin>>m; rep(i,m){ cin>>x[i]>>y[i]; } ll R=findSwapPairs(n,s,m,x,y,p,q); cout<<"R="<<R<<endl; rep(i,R)cout<<"PQ:"<<p[i]<<" "<<q[i]<<endl; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:31:8: warning: declaration of 'R' shadows a previous local [-Wshadow]
    int R=0;
        ^
sorting.cpp:16:6: note: shadowed declaration is here
  int R=0;
      ^
sorting.cpp:36:18: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
      P[R]=i,Q[R]=p,R++;
                  ^
sorting.cpp:14:6: warning: variable 'ss' set but not used [-Wunused-but-set-variable]
  int ss[2010];
      ^~
sorting.cpp:13:37: warning: unused parameter 'M' [-Wunused-parameter]
 int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
                                     ^
sorting.cpp:35:5: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if(i!=p){
     ^~
sorting.cpp:25:4: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(i!=p){
    ^~
/tmp/ccf9fDyt.o: In function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'
/tmp/cc15bcLb.o:sorting.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status