# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
669 | pl0892029 | 쉬운 문제 (GA3_easy) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <grader.h>
void GetBestAnswer(int N,int *S,int K)
{
int bucket[10][100], pos[100], top[10]={0,}, bot[10]={0,};
int num[10]={0,1,2,3,4,5,6,7,8,9};
int i,j,k,l,m;
for(i=0;i<N;i++)
bucket[S[i]][top[S[i]]++]=i, pos[i]=1;
for(i=1;i<10;i++) for(j=i+1;j<10;j++) // quad check
for(k=j+1;k<10;k++)for(l=k+1;l<10;l++)
{
if(i+j==k || i+j==l || i+k==l || j+k==l) continue;
if(i+j+k==l) continue;
while(K>0)
{
if(bot[i]==top[i] || bot[j]==top[j]) break;
if(bot[k]==top[k] || bot[l]==top[l]) break;
Mark(bucket[i][bot[i]],pos[bucket[i][bot[i]]]);
Mark(bucket[j][bot[j]],pos[bucket[j][bot[j]]]);
Mark(bucket[k][bot[k]],pos[bucket[k][bot[k]]]);
Mark(bucket[l][bot[l]],pos[bucket[l][bot[l]]]);
K--;
m=GetScore();
if( m==i+j+k+l ) bot[i]++, bot[j]++, bot[k]++, bot[l]++; // quad
else if( m==i+j+k ) bot[i]++, bot[j]++, bot[k]++, pos[bucket[l][bot[l]]]++;
else if( m==i+j+l ) bot[i]++, bot[j]++, pos[bucket[k][bot[k]]]++, bot[l]++;
else if( m==i+k+l ) bot[i]++, pos[bucket[j][bot[j]]]++, bot[k]++, bot[l]++;
else if( m==j+k+l ) pos[bucket[i][bot[i]]]++, bot[j]++, bot[k]++, bot[l]++; // tri
else if( m==i+j ) bot[i]++, bot[j]++, pos[bucket[k][bot[k]]]++, pos[bucket[l][bot[l]]]++;
else if( m==i+k ) bot[i]++, pos[bucket[j][bot[j]]]++, bot[k]++, pos[bucket[l][bot[l]]]++;
else if( m==i+l ) bot[i]++, pos[bucket[j][bot[j]]]++, pos[bucket[k][bot[k]]]++, bot[l]++;
else if( m==j+k ) pos[bucket[i][bot[i]]]++, bot[j]++, bot[k]++, pos[bucket[l][bot[l]]]++;
else if( m==j+l ) pos[bucket[i][bot[i]]]++, bot[j]++, pos[bucket[k][bot[k]]]++, bot[l]++;
else if( m==k+l ) pos[bucket[i][bot[i]]]++, pos[bucket[j][bot[j]]]++, bot[k]++, bot[l]++; // dou
else if( m==i ) bot[i]++, pos[bucket[j][bot[j]]]++, pos[bucket[k][bot[k]]]++, pos[bucket[l][bot[l]]]++;
else if( m==j ) pos[bucket[i][bot[i]]]++, bot[j]++, pos[bucket[k][bot[k]]]++, pos[bucket[l][bot[l]]]++;
else if( m==k ) pos[bucket[i][bot[i]]]++, pos[bucket[j][bot[j]]]++, bot[k]++, pos[bucket[l][bot[l]]]++;
else if( m==l ) pos[bucket[i][bot[i]]]++, pos[bucket[j][bot[j]]]++, pos[bucket[k][bot[k]]]++, bot[l]++; // sin
else pos[bucket[i][bot[i]]]++, pos[bucket[j][bot[j]]]++, pos[bucket[k][bot[k]]]++, pos[bucket[l][bot[l]]]++; // none
if(pos[bucket[i][bot[i]]]==5) bot[i]++;
if(pos[bucket[j][bot[j]]]==5) bot[j]++;
if(pos[bucket[k][bot[k]]]==5) bot[k]++;
if(pos[bucket[l][bot[l]]]==5) bot[l]++;
}
}
for(i=1;i<10;i++) for(j=i+1;j<10;j++) // tri check
for(k=j+1;k<10;k++)
{
if(i+j==k) continue;
while(K>0)
{
if(bot[i]==top[i] || bot[j]==top[j]) break;
if(bot[k]==top[k]) break;
Mark(bucket[i][bot[i]],pos[bucket[i][bot[i]]]);
Mark(bucket[j][bot[j]],pos[bucket[j][bot[j]]]);
Mark(bucket[k][bot[k]],pos[bucket[k][bot[k]]]);
K--;
m=GetScore();
if( m==i+j+k ) bot[i]++, bot[j]++, bot[k]++; // tri
else if( m==i+j ) bot[i]++, bot[j]++, pos[bucket[k][bot[k]]]++;
else if( m==i+k ) bot[i]++, pos[bucket[j][bot[j]]]++, bot[k]++;
else if( m==j+k ) pos[bucket[i][bot[i]]]++, bot[j]++, bot[k]++; // dou
else if( m==i ) bot[i]++, pos[bucket[j][bot[j]]]++, pos[bucket[k][bot[k]]]++;
else if( m==j ) pos[bucket[i][bot[i]]]++, bot[j]++, pos[bucket[k][bot[k]]]++;
else if( m==k ) pos[bucket[i][bot[i]]]++, pos[bucket[j][bot[j]]]++, bot[k]++; // sin
else pos[bucket[i][bot[i]]]++, pos[bucket[j][bot[j]]]++, pos[bucket[k][bot[k]]]++; // none
if(pos[bucket[i][bot[i]]]==5) bot[i]++;
if(pos[bucket[j][bot[j]]]==5) bot[j]++;
if(pos[bucket[k][bot[k]]]==5) bot[k]++;
}
}
for(i=1;i<10;i++) for(j=i+1;j<10;j++) // dou check
{
while(K>0)
{
if(bot[i]==top[i] || bot[j]==top[j]) break;
Mark(bucket[i][bot[i]],pos[bucket[i][bot[i]]]);
Mark(bucket[j][bot[j]],pos[bucket[j][bot[j]]]);
K--;
m=GetScore();
if( m==i+j ) bot[i]++, bot[j]++; // dou
else if( m==i ) bot[i]++, pos[bucket[j][bot[j]]]++;
else if( m==j ) pos[bucket[i][bot[i]]]++, bot[j]++; // sin
else pos[bucket[i][bot[i]]]++, pos[bucket[j][bot[j]]]++; // none
if(pos[bucket[i][bot[i]]]==5) bot[i]++;
if(pos[bucket[j][bot[j]]]==5) bot[j]++;
}
}
for(i=1;i<10;i++)
{
while(K>0)
{
if(bot[i]==top[i]) break;
Mark(bucket[i][bot[i]],pos[bucket[i][bot[i]]]);
K--;
m=GetScore();
if( m==i ) bot[i]++; // sin
else pos[bucket[i][bot[i]]]++; // none
if(pos[bucket[i][bot[i]]]==5) bot[i]++;
}
}
for(i=0;i<N;i++) Report(pos[i]);
}