Submission #687664

# Submission time Handle Problem Language Result Execution time Memory
687664 2023-01-26T18:33:58 Z speedyArda Red-blue table (IZhO19_stones) C++14
100 / 100
81 ms 2216 KB
#include "bits/stdc++.h"

using namespace std;

int main() 
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, m;
        cin >> n >> m;
        char ans[n+5][m+5];

        set<pair<int, int> > touse;
        int res = 0;
        if(n + (n/2) > m + (m/2))
        {
            for(int i = 1; i <= n; i++)
                for(int a = 1; a <= m; a++)
                    ans[i][a] = '+';
            res = n;
            for(int i = 1; i <= n; i++)
                touse.insert({0, i});
             for(int i = 1; i <= m; i++)
            {
                int curr = 0;
                bool valid = true;
                while(curr <= n / 2)
                {
                    pair<int, int> front = *(touse.begin());
                    if(front.first + 1 >= (m+1) / 2) {
                        valid = false;
                        break;
                    }
                    front.first++;
                    ans[front.second][i] = '-';
                    touse.erase(touse.begin());
                    touse.insert(front);
                    curr++;
                    //cout << curr << " " << front.first << " " << front.second << "\n";
                }
                if(!valid)
                    break;
                res++;
            }
        } else 
        {
            for(int i = 1; i <= n; i++)
                for(int a = 1; a <= m; a++)
                    ans[i][a] = '-';
            res = m;
            for(int i = 1; i <= m; i++)
                touse.insert({0, i});
            for(int i = 1; i <= n; i++)
            {
                int curr = 0;
                bool valid = true;
                while(curr <= m / 2)
                {
                    pair<int, int> front = *(touse.begin());
                    if(front.first + 1 >= (n+1) / 2) {
                        valid = false;
                        break;
                    }
                    front.first++;
                    ans[i][front.second] = '+';
                    touse.erase(touse.begin());
                    touse.insert(front);
                    curr++;
                    
                }
                if(!valid)
                    break;
                res++;
            }
        }

        cout << res << "\n";
        for(int i = 1; i <= n; i++) {
            for(int a = 1; a <= m; a++) {
                cout << ans[i][a];
            }
            cout << "\n";
        }
    }   
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 1212 KB Output is correct
2 Correct 71 ms 1880 KB Output is correct
3 Correct 69 ms 1804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 1212 KB Output is correct
2 Correct 65 ms 1612 KB Output is correct
3 Correct 58 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 81 ms 1212 KB Output is correct
6 Correct 71 ms 1880 KB Output is correct
7 Correct 69 ms 1804 KB Output is correct
8 Correct 75 ms 1212 KB Output is correct
9 Correct 65 ms 1612 KB Output is correct
10 Correct 58 ms 1360 KB Output is correct
11 Correct 17 ms 512 KB Output is correct
12 Correct 60 ms 1492 KB Output is correct
13 Correct 69 ms 1444 KB Output is correct
14 Correct 46 ms 1116 KB Output is correct
15 Correct 79 ms 2216 KB Output is correct
16 Correct 66 ms 1684 KB Output is correct
17 Correct 27 ms 912 KB Output is correct