Submission #345493

# Submission time Handle Problem Language Result Execution time Memory
345493 2021-01-07T13:29:11 Z georgerapeanu Red-blue table (IZhO19_stones) C++11
100 / 100
65 ms 9836 KB
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int t;
int n,m;

int main(){
    
    scanf("%d",&t);

    while(t--){
        scanf("%d %d",&n,&m);

        bool sw = (n > m);
        if(sw){
            swap(n,m);
        }

        vector<vector<int> > ans(n + 1,vector<int>(m + 1));

        int cnt_available = max(0,(n - 1) / 2) - 1;
        int lst = 1;
        int ans_sum = m;

        for(int i = 1;i <= n && cnt_available >= 0;i++){
            bool success = true;
            for(int j = 0;j < m / 2 + 1;j++){
                ans[i][lst] = 1;
                lst++;
                if(lst > m){
                    lst = 1;
                    cnt_available--;
                    if(cnt_available < 0 && j < m / 2){
                        success = false;
                        break;
                    }
                }
            }
            ans_sum += success;
        }

        if(sw){
            swap(n,m);
            vector<vector<int> > tmp(n + 1,vector<int>(m + 1));
            for(int i = 1;i <= n;i++){
                for(int j = 1;j <= m;j++){
                    tmp[i][j] = ans[j][i] ^ 1;
                }
            }
            ans = tmp;
        }
        
        printf("%d\n",ans_sum);
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= m;j++){
                printf(ans[i][j] == 0 ? "-":"+");
            }
            printf("\n");
        }

    }

    return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     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 time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 1516 KB Output is correct
2 Correct 42 ms 3948 KB Output is correct
3 Correct 44 ms 9836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1516 KB Output is correct
2 Correct 44 ms 3012 KB Output is correct
3 Correct 45 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 49 ms 1516 KB Output is correct
6 Correct 42 ms 3948 KB Output is correct
7 Correct 44 ms 9836 KB Output is correct
8 Correct 45 ms 1516 KB Output is correct
9 Correct 44 ms 3012 KB Output is correct
10 Correct 45 ms 2392 KB Output is correct
11 Correct 13 ms 544 KB Output is correct
12 Correct 41 ms 6224 KB Output is correct
13 Correct 41 ms 4576 KB Output is correct
14 Correct 38 ms 2796 KB Output is correct
15 Correct 65 ms 5228 KB Output is correct
16 Correct 44 ms 3948 KB Output is correct
17 Correct 17 ms 4460 KB Output is correct