Submission #687669

# Submission time Handle Problem Language Result Execution time Memory
687669 2023-01-26T18:40:58 Z speedyArda Red-blue table (IZhO19_stones) C++14
100 / 100
76 ms 2208 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 + ((m-1)/2) > m + ((n-1)/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 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 1296 KB Output is correct
2 Correct 70 ms 1748 KB Output is correct
3 Correct 64 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 1228 KB Output is correct
2 Correct 61 ms 1612 KB Output is correct
3 Correct 56 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 75 ms 1296 KB Output is correct
6 Correct 70 ms 1748 KB Output is correct
7 Correct 64 ms 1868 KB Output is correct
8 Correct 70 ms 1228 KB Output is correct
9 Correct 61 ms 1612 KB Output is correct
10 Correct 56 ms 1368 KB Output is correct
11 Correct 18 ms 528 KB Output is correct
12 Correct 60 ms 1400 KB Output is correct
13 Correct 61 ms 1436 KB Output is correct
14 Correct 46 ms 1112 KB Output is correct
15 Correct 76 ms 2208 KB Output is correct
16 Correct 55 ms 1776 KB Output is correct
17 Correct 26 ms 964 KB Output is correct