Submission #344114

# Submission time Handle Problem Language Result Execution time Memory
344114 2021-01-05T07:16:25 Z Rakhmand Red-blue table (IZhO19_stones) C++14
100 / 100
110 ms 2412 KB
//
//  C.cpp
//  torelax
//
//  Created by Rakhman on 1/5/21.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)

const long long mxn = 1e6 + 110;
const long long mnn = 1e3 + 2;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long OO = 1e9;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, m;
char ch[mnn][mnn];

void solve(){
    int mx = 0, rows = -1, cols = -1;
    bool swapped = false;
    cin >> n >> m;
    if(n < m) {
        swapped = true;
        swap(n, m);
    }
    for(int i = 0; i <= n; i++){
        int x = (m - 1) / 2 * (n - i);
        llong col = x / ((n + 2) / 2);
        int lol = n - i + col;
        if(lol > mx){
            mx = lol;
            rows = i;
            cols = col;
        }
        if(col == m){
            break;
        }
    }
    cout << mx << nl;
    for(int i = 1; i <= rows; i++){
        for(int j = 1; j <= m; j++){
            ch[i][j] = (swapped == true ? '+' : '-');
        }
        cout << nl;
    }
    for(int i = 1; i <= n - rows; i++){
        for(int j = 1; j <= m; j++){
            ch[i][j] = (swapped == true ? '-' : '+');
        }
    }
    set<pair<int, int> > st;
    for(int i = m - cols + 1; i <= m; i++){
        st.insert({-1 * (n + 2) / 2 - rows, i});
    }
    for(int i = 1; i <= n - rows; i++){
        vector<pair<int, int> > v;
        for(int j = 1; j <= (m - 1) / 2; j++){
            if(st.size() == 0) break;
            pair<int, int> x = *(st.begin());
            st.erase(st.begin());
            ch[i][x.S] = (swapped == true ? '+' : '-');
            v.push_back({x.F, x.S});
        }
        for(int j = 0; j < v.size(); j++){
            if(v[j].F + 1 == 0) continue;
            st.insert({v[j].F + 1, v[j].S});
        }
    }
    if(swapped == 1){
        for(int j = 1; j <= m; j++){
            for(int i = 1; i <= n; i++){
                cout << ch[i][j];
            }
            cout << nl;
        }
    }else{
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                cout << ch[i][j];
            }
            cout << nl;
        }
    }
}

int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:102:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         for(int j = 0; j < v.size(); j++){
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 1516 KB Output is correct
2 Correct 99 ms 2156 KB Output is correct
3 Correct 98 ms 2156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 1516 KB Output is correct
2 Correct 92 ms 1900 KB Output is correct
3 Correct 87 ms 1668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 100 ms 1516 KB Output is correct
6 Correct 99 ms 2156 KB Output is correct
7 Correct 98 ms 2156 KB Output is correct
8 Correct 105 ms 1516 KB Output is correct
9 Correct 92 ms 1900 KB Output is correct
10 Correct 87 ms 1668 KB Output is correct
11 Correct 21 ms 640 KB Output is correct
12 Correct 110 ms 1900 KB Output is correct
13 Correct 89 ms 2028 KB Output is correct
14 Correct 73 ms 1772 KB Output is correct
15 Correct 108 ms 2412 KB Output is correct
16 Correct 84 ms 2028 KB Output is correct
17 Correct 34 ms 1388 KB Output is correct