Submission #788586

#TimeUsernameProblemLanguageResultExecution timeMemory
788586BidoTeimaRed-blue table (IZhO19_stones)C++17
100 / 100
73 ms2208 KiB
#include <bits/stdc++.h>
using namespace std;  
int main() { 
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        bool s = 0;
        if(n < m){
            swap(n, m);
            s = 1;
        }
        char grid[n][m];
        multiset<pair<int,int>>ms;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                grid[i][j]='+';
            }
            if((m-1)/2){
                ms.insert({(m-1)/2, i});
            }
        }
        int c=0;
        while(ms.size() >= n/2+1){
            if(ms.size()>=n/2+1){c++;}
            vector<multiset<pair<int,int>>::iterator>toErase;
            int iter=0;
            for(auto it = prev(ms.end()); iter<n/2+1; --it,++iter){
                toErase.push_back(it);
                grid[it->second][c - 1] = '-';
            }
            for(auto it:toErase){
                int val=it->first,row=it->second;
                ms.erase(it);
                if(val != 1){
                    ms.insert({val - 1, row});
                }
            }
        } 
        cout<<n+c<<'\n';
        if(s){
            for(int j = 0; j < m; j++){
                for(int i = 0; i < n; i++){
                    cout<<(grid[i][j]=='+'?'-':'+');
                }
                cout<<'\n';
            }
        }else{
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                    cout<<grid[i][j];
                }
                cout<<'\n';
            }
        }
    }
    return 0;
}

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:25:25: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |         while(ms.size() >= n/2+1){
      |               ~~~~~~~~~~^~~~~~~~
stones.cpp:26:25: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |             if(ms.size()>=n/2+1){c++;}
      |                ~~~~~~~~~^~~~~~~
#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...