Submission #687669

#TimeUsernameProblemLanguageResultExecution timeMemory
687669speedyArdaRed-blue table (IZhO19_stones)C++14
100 / 100
76 ms2208 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...