답안 #788586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
788586 2023-07-20T11:34:55 Z BidoTeima Red-blue table (IZhO19_stones) C++17
100 / 100
73 ms 2208 KB
#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

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++;}
      |                ~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 1188 KB Output is correct
2 Correct 51 ms 1752 KB Output is correct
3 Correct 56 ms 1796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1248 KB Output is correct
2 Correct 58 ms 1544 KB Output is correct
3 Correct 44 ms 1340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 56 ms 1188 KB Output is correct
6 Correct 51 ms 1752 KB Output is correct
7 Correct 56 ms 1796 KB Output is correct
8 Correct 55 ms 1248 KB Output is correct
9 Correct 58 ms 1544 KB Output is correct
10 Correct 44 ms 1340 KB Output is correct
11 Correct 13 ms 468 KB Output is correct
12 Correct 45 ms 1484 KB Output is correct
13 Correct 55 ms 1448 KB Output is correct
14 Correct 39 ms 1056 KB Output is correct
15 Correct 73 ms 2208 KB Output is correct
16 Correct 45 ms 1696 KB Output is correct
17 Correct 19 ms 940 KB Output is correct