Submission #549294

# Submission time Handle Problem Language Result Execution time Memory
549294 2022-04-15T14:35:19 Z krit3379 Red-blue table (IZhO19_stones) C++17
0 / 100
104 ms 5760 KB
#include<bits/stdc++.h>
using namespace std;
#define N 1005

int board[N][N],cnt[N];
priority_queue<pair<int,int>> q,t;

void sol(){
    int n,m,nn,mm,ma,ans,a,i,j,cou;
    scanf("%d %d",&n,&m);
    nn=n/2+1;
    mm=m/2+1;
    ans=0,ma=a=n;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++)board[i][j]=0;
        cnt[i]=m;
    }
    for(i=1;i<=m;i++){
        for(j=1;j<=n;j++){
            if(cnt[j]>=mm)q.push({cnt[j],j});
            else t.push({cnt[j],j});
        }
        cou=nn;
        while(!t.empty()&&cou--){
            auto [x,y]=t.top();
            t.pop();
            cnt[y]--;
            board[y][i]=1;
        }
        while(!q.empty()&&cou--){
            auto [x,y]=q.top();
            q.pop();
            if(--cnt[y]<mm)a--;
            board[y][i]=1;
        }
        if(a+i>ma)ma=a+i,ans=i;
    }
    printf("%d\n",ma);
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(j<=ans)printf("%c",board[i][j]?'-':'+');
            else printf("+");
        }
        printf("\n");
    }
}

int main(){
    int t;
    scanf("%d",&t);
    while(t--)sol();
    return 0;
}

Compilation message

stones.cpp: In function 'void sol()':
stones.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
stones.cpp: In function 'int main()':
stones.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 1 ms 212 KB Wrong answer in test 4 3: 4 < 5
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 596 KB in the table A+B is not equal to 46
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 1 ms 212 KB Wrong answer in test 4 3: 4 < 5
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 5640 KB in the table A+B is not equal to 107
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 5760 KB in the table A+B is not equal to 35
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 1 ms 212 KB Wrong answer in test 4 3: 4 < 5
3 Halted 0 ms 0 KB -