


CodePudding user response:
Timeout is too slow, to find a way to improve efficiency,Digging well array, lower cycle times, don't have a double loop,
CodePudding user response:
Reference:# include & lt; Stdio. H>
Int main (int arg c, char * argv [])
{
Int n, flag=1;
The scanf (" % d ", & amp; n);
Int * a=new int [n].
Int * b=new int [n].
Memset (a, 0, sizeof (int) * n);
Memset (b, 0, sizeof (int) * n);
for(int i=0; iThe scanf (" % d ", & amp; A [I]);
for(int i=0; iFor (int j=0; j If (a==[I] a [j])
B [I] + +;
}
for(int i=0; iIf (b [I]==1) {
Printf (" % d \ n ", a [I]);
Flag=0;
break;
}
If (flag) printf (" None \ n ");
The delete [] a;
The delete [] b;
return 0;
}
CodePudding user response:
Try not to in C code in C + + syntax,This does not solve the problem of the timeout,
CodePudding user response:
Can try like this:
# include & lt; Stdio. H>
Int a [100000], [100000] b;
Int main ()
{
Int n, I;
The scanf (" % d ", & amp; n);
For (I=0; I & lt; n; I++)
{
The scanf (" % d ", a + I);
B [a] [I] + +;
}
For (I=0; I & lt; n; I++)
{
If (b [a] [I]==1)
{
Printf (" % d \ n ", a [I]);
return 0;
}
}
Printf (" None \ n ");
return 0;
}