Submission #683310

# Submission time Handle Problem Language Result Execution time Memory
683310 2023-01-18T07:10:52 Z FatihSolak Red-blue table (IZhO19_stones) C++17
100 / 100
82 ms 2252 KB

    #include <bits/stdc++.h>
    #define N 1005
    using namespace std;
    char ans[N][N];
    void solve(){
        int a,b;
        cin >> a >> b;
        if(a <= b){
            for(int i = 0;i<a;i++){
                for(int j = 0;j<b;j++){
                    ans[i][j] = '-';
                }
            }
            int num = a - (a/2 + 1);
            int res = b;
            set<pair<int,int>> s;
            int maxi = num * b / (b/2 + 1);
            for(int i = 0;i<min(a,maxi);i++){
                s.insert({-(b/2 + 1),i});
            }
            for(int i = 0;i<b && s.size();i++){
                vector<pair<int,int>> use;
                while(s.size() && use.size() < num){
                    use.push_back(*s.begin());
                    s.erase(s.begin());
                }
                for(auto u:use){
                    u.first++;
                    ans[u.second][i] = '+';
                    if(u.first)
                        s.insert(u);
                    else res++;
                }
            }
            cout << res << '\n';
            for(int i = 0;i<a;i++){
                for(int j = 0;j<b;j++){
                    cout << ans[i][j];
                }
                cout << '\n';
            }
        }
        else{
            for(int i = 0;i<a;i++){
                for(int j = 0;j<b;j++){
                    ans[i][j] = '+';
                }
            }
            int num = b - (b/2 + 1);
            int res = a;
            set<pair<int,int>> s;
            int maxi = num * a / (a/2 + 1);
            for(int i = 0;i<min(maxi,b);i++){
                s.insert({-(a/2 + 1),i});
            }
            for(int i = 0;i<a && s.size();i++){
                vector<pair<int,int>> use;
                while(s.size() && use.size() < num){
                    use.push_back(*s.begin());
                    s.erase(s.begin());
                }
                for(auto u:use){
                    u.first++;
                    ans[i][u.second] = '-';
                    if(u.first)
                        s.insert(u);
                    else res++;
                }
            }
            cout << res << '\n';
            for(int i = 0;i<a;i++){
                for(int j = 0;j<b;j++){
                    cout << ans[i][j];
                }
                cout << '\n';
            }
        }
    }
     
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        #ifdef Local
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
        int t=1;
        cin>>t;
        while(t--){
            solve();
        }
        #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
        #endif
    }

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:25:46: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |                 while(s.size() && use.size() < num){
      |                                   ~~~~~~~~~~~^~~~~
stones.cpp:60:46: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |                 while(s.size() && use.size() < num){
      |                                   ~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1344 KB Output is correct
2 Correct 72 ms 1996 KB Output is correct
3 Correct 67 ms 2124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 1376 KB Output is correct
2 Correct 64 ms 1820 KB Output is correct
3 Correct 65 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 68 ms 1344 KB Output is correct
6 Correct 72 ms 1996 KB Output is correct
7 Correct 67 ms 2124 KB Output is correct
8 Correct 78 ms 1376 KB Output is correct
9 Correct 64 ms 1820 KB Output is correct
10 Correct 65 ms 1628 KB Output is correct
11 Correct 14 ms 524 KB Output is correct
12 Correct 67 ms 1876 KB Output is correct
13 Correct 76 ms 1996 KB Output is correct
14 Correct 52 ms 1652 KB Output is correct
15 Correct 82 ms 2252 KB Output is correct
16 Correct 68 ms 1784 KB Output is correct
17 Correct 28 ms 1236 KB Output is correct