Submission #308777

# Submission time Handle Problem Language Result Execution time Memory
308777 2020-10-01T23:01:44 Z nikatamliani Red-blue table (IZhO19_stones) C++14
17 / 100
97 ms 1400 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int T = 1;
    cin >> T;
    while(T--) {
        int n, m;
        cin >> n >> m;
        bool ans[n + 1][m + 1];
        bool swapped = 0;
        memset(ans, 0, sizeof ans);
        if(n < m) {
            swap(n, m);
            swapped = true; 
        }
        set < pair < int, int > > counts;
        vector < int > good;
        for(int i = 1; i <= m; ++i) counts.insert({0, i}); 
        for(int i = 1; i <= n; ++i) {
            int cnt = m / 2 + 1;
            for(int j : good) {
                if(cnt == 0)break;
                cnt--;
                ans[i][j] = 1; 
            }
            while(cnt > 0) {
                auto [x, y] = *counts.begin();
                counts.erase(counts.begin());
                ++x;
                if(n - x <= x) {
                    good.push_back(y);
                } else {
                    counts.insert({x, y});
                }
                ans[i][y] = 1;
                cnt--;
            }
        }
        vector < int > row(n + 1), col(m + 1);
        for(int i = 1; i <= n; ++i) {
            for(int j = 1; j <= m; ++j) {
                if(ans[i][j]) {
                    ++row[i], --col[j];
                } else {
                    --row[i], ++col[j];
                }
            }
        }
        int best = 0;
        for(int i = 1; i <= n; ++i) best += row[i] > 0;
        for(int i = 1; i <= m; ++i) best += col[i] > 0;
        cout << best << '\n';
        if(!swapped) {
            for(int i = 1; i <= n; ++i) {
                for(int j = 1; j <= m; ++j) {
                    cout << (ans[i][j] ? '+' : '-'); 
                }
                cout << '\n';
            }
        } else {
            for(int i = 1; i <= m; ++i) {
                for(int j = 1; j <= n; ++j) {
                    cout << (ans[j][i] ? '-' : '+');
                }
                cout << '\n';
            }
        }
    }
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:27:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |                 auto [x, y] = *counts.begin();
      |                      ^
# 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 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 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 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 1400 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# 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 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)