답안 #162871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162871 2019-11-10T07:15:45 Z abacaba Red-blue table (IZhO19_stones) C++14
11 / 100
26 ms 4976 KB
#include <chrono>
#include <random>
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <vector>
#include <map>
#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;

const int mod = 1e9 + 7;
const int inf = 1e9;
const int N = 1e3 + 15;
int t, n, m, a[N][N];
int red_in_row[N], red_in_col[N];

inline void make_red(int i, int j) {
    a[i][j] = 1, ++red_in_row[i], ++red_in_col[j];
}

inline void make_blue(int i, int j) {
    a[i][j] = 0, --red_in_row[i], --red_in_col[j];
}

inline void paint() {
    if(n >= m) {
        for(int i = 1; i < n / 2 + (n & 1); ++i)
            for(int j = 1; j <= m / 2 + 1; ++j)
                make_red(i, j);
        for(int i = n; i > n / 2 + 1; --i)
            for(int j = m; j >= m / 2 + (m & 1); --j)
                make_red(i, j);
    }
    else {
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= m; ++j)
                make_red(i, j);
        for(int i = 1; i <= n / 2 + 1; ++i)
            for(int j = 1; j < m / 2 + (m & 1); ++j)
                make_blue(i, j);
        for(int i = n; i >= n / 2 + (n & 1); --i)
            for(int j = m; j > m / 2 + 1; --j)
                make_blue(i, j);
    }
}

main() {
    scanf("%d", &t);
    while(t--) {
        int ans = 0;
        for(int i = 1; i <= n; ++i) {
            red_in_row[i] = 0;
            for(int j = 1; j <= m; ++j)
                a[i][j] = red_in_col[j] = 0;
        }
        scanf("%d %d", &n, &m);
        paint();
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= m; ++j) {
                if(red_in_col[j] * 2 >= n && !a[i][j])
                    make_red(i, j);
                if(red_in_row[i] * 2 < m && a[i][j])
                    make_blue(i, j);
            }
        for(int i = 1; i <= n; ++i)
            ans += (2 * red_in_row[i] > m);
        for(int j = 1; j <= m; ++j)
            ans += (2 * red_in_col[j] < n);
        printf("%d\n", ans);
        for(int i = 1; i <= n; ++i, puts(""))
            for(int j = 1; j <= m; ++j)
                putchar(a[i][j] == 1 ? '+' : '-');
    }
    return 0;
}

Compilation message

stones.cpp:58:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
stones.cpp: In function 'int main()':
stones.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &t);
     ~~~~~^~~~~~~~~~
stones.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &n, &m);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 296 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 2 1: 1 < 2
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 632 KB Wrong answer in test 2 1: 1 < 2
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 296 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 2 1: 1 < 2
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1712 KB Output is correct
2 Correct 26 ms 4188 KB Output is correct
3 Correct 23 ms 4976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 1916 KB Wrong answer in test 4 4: 4 < 5
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 296 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 2 1: 1 < 2