제출 #371156

#제출 시각아이디문제언어결과실행 시간메모리
371156daniel920712Red-blue table (IZhO19_stones)C++14
0 / 100
65 ms1880 KiB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
int all[1005][1005];
int con[1005];
int main()
{
    int T,N,M,ans=0,i,j,k,ok=1;
    scanf("%d",&T);
    while(T--)
    {
        ans=0,ok=0;
        scanf("%d %d",&N,&M);
        if(N>M)
        {
            ok=1;
            swap(N,M);
        }
        if(N<=M)
        {
            ans=M;
            for(i=0;i<=N/2;i++)
            {
                con[i]=0;
                for(j=0;j<M;j++) all[i][j]=0;
            }
            for(i=N/2+1;i<N;i++)
            {
                con[i]=M;
                for(j=0;j<M;j++) all[i][j]=1;
            }

            for(i=0;i<=N/2;i++)
            {
                for(j=0;j<M;j++)
                {
                    if(con[i]<=(M-con[i]))
                    {
                        for(k=N/2+1;k<=N;k++)
                        {
                            if(all[k][j]==1)
                            {
                                if(con[k]-1>(M-con[k]+1))
                                {
                                    con[k]--;
                                    con[i]++;
                                    swap(all[i][j],all[k][j]);
                                }
                            }
                        }
                    }
                }
            }

            ans=M;
            for(i=0;i<N;i++) if(con[i]>(M-con[i])) ans++;
        }
        if(ok==0)
        {
            printf("%d\n",ans);
            for(i=0;i<N;i++)
            {
                for(j=0;j<M;j++)
                {
                    if(all[i][j]==0) printf("-");
                    else printf("+");
                }
                printf("\n");
            }
        }
        else
        {

            printf("%d\n",ans);
            for(i=0;i<M;i++)
            {
                for(j=0;j<N;j++)
                {
                    if(all[j][i]==1) printf("-");
                    else printf("+");
                }
                printf("\n");
            }
        }

    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

stones.cpp: In function 'int main()':
stones.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |     scanf("%d",&T);
      |     ~~~~~^~~~~~~~~
stones.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         scanf("%d %d",&N,&M);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...