제출 #166805

#제출 시각아이디문제언어결과실행 시간메모리
166805YaroslaffRed-blue table (IZhO19_stones)C++14
100 / 100
121 ms5316 KiB
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
const int inf = 2e9;
const int N = 1e3 + 15;
int t, n, m, a[N][N], row[N], col[N];
 
inline void make_red(int i, int j) {
    a[i][j] = 1, ++row[i], ++col[j];
}
 
inline void make_blue(int i, int j) {
    a[i][j] = 0, --row[i], --col[j];
}
 
main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    cin >> t;
    while(t--) {
        int ans = 0;
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= m; ++j)
                a[i][j] = row[i] = col[j] = 0;
        cin >> n >> m;
        if(n <= m) {
            for(int i = 1; i <= n; ++i) {
                vector <pii> pot = {};
                for(int j = 1; j <= m; ++j)
                    if(2 * (col[j] + 1) < n)
                        pot.pb({col[j], j});
                if(pot.size() < m / 2 + 1)
                    break;
                sort(pot.begin(), pot.end());
                for(int j = 0; j <= m / 2; ++j)
                    make_red(i, pot[j].se);
            }
        }
        else {
            for(int i = 1; i <= n; ++i)
                for(int j = 1; j <= m; ++j)
                    make_red(i, j);
            for(int j = 1; j <= m; ++j) {
                vector <pii> pot = {};
                for(int i = 1; i <= n; ++i)
                    if(2 * (row[i] - 1) > m)
                        pot.pb({row[i], i});
                if(pot.size() < n / 2 + 1)
                    break;
                sort(pot.begin(), pot.end(), [&](pii a, pii b) {
                    return a > b;
                });
                for(int i = 0; i <= n / 2; ++i)
                    make_blue(pot[i].se, j);
            }
        }
        for(int i = 1; i <= n; ++i)
            ans += 2 * row[i] > m;
        for(int i = 1; i <= m; ++i)
            ans += 2 * col[i] < n;
        cout << ans << endl;
        for(int i = 1; i <= n; ++i, cout << endl)
            for(int j = 1; j <= m; ++j)
                cout << (a[i][j] ? '+' : '-');
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

stones.cpp:53:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
stones.cpp: In function 'int main()':
stones.cpp:68:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(pot.size() < m / 2 + 1)
                    ~~~~~~~~~~~^~~~~~~~~~~
stones.cpp:84:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(pot.size() < n / 2 + 1)
                    ~~~~~~~~~~~^~~~~~~~~~~
#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...