Here is my code in C++ i tried a lot and i didn't find anything , i would
appreciate if someone finds where the error is.
#pragma GCC optimize "O3,inline"
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;
int checkSort(int *even,int *odd,int len){
int i=0;
while(i<(len-1)/2){
if(even[i]>odd[i]){
return 2*i;
}else if(odd[i]>even[i+1]){
return 2*i+1;
}
++i;
}
return -1;
}
int main() {
int N;
cin>>N;cin.ignore();
char *buff=(char *)malloc(500000);
int *evenlist=(int *)malloc(4*200000);
int *oddlist=(int *)malloc(4*200000);
for(int i=0;i<N;i++){
int len,len0,len1;
cin>>len;cin.ignore();
len0=(len+1)/2;
len1=len/2;
cin.read(buff,len*2 - 1);cin.ignore();
for(int j=0;j<len/2;j++){
evenlist[j]=buff[4*j]-48;
oddlist[j]=buff[4*j + 2]-48;
}
if(len%2==1){
evenlist[len0-1]=buff[4*(len0-1)]-48;
}
sort(evenlist,evenlist+len0);
sort(oddlist,oddlist+len1);
int check=checkSort(evenlist,oddlist,len);
if(check==-1){
cout<<"Case #"<<i+1<<": OK"<<endl;
}else{
cout<<"Case #"<<i+1<<": "<<check<<endl;
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/b8903bd2-756b-48e5-87e7-ad2bc7028a81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.