답안 #382212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382212 2021-03-26T17:25:34 Z BartolM Red-blue table (IZhO19_stones) C++17
54 / 100
78 ms 8832 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=1005;

int n, m, fl;
int mat[N][N], pom[N][N], red[N], stup[N];

void mali_stup() {
    return;
}

void poseban_4() {
    for (int i=0; i<n; ++i) mat[i][0]=1;
}

void poseb56() {
    int br=(m+1)/2;
    for (int i=0; i<n; ++i) {
        for (int j=m/2; j<m; ++j) mat[i][j]=1;
        int j=m/2+i%br;
        mat[i][j]=0;
    }
}

void pos_stup() {
    for (int i=0; i<n; ++i) {
        for (int j=0; j<m/2-!(m%2); ++j) mat[i][j]=1;
    }
}

void reset() {
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j) pom[i][j]=mat[i][j]=0;
}

void rotiraj() {
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
            pom[j][n-i-1]=mat[i][j];
    swap(n, m);
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
            mat[i][j]=!pom[i][j];
}

void poseb8() {
    int aa=3, bb=4;
    for (int i=0; i<n; ++i) {
        for (int j=3; j<m; ++j) mat[i][j]=1;
        mat[i][aa]=0;
        mat[i][bb]=0;
        aa++; if (aa>=m) aa=3;
        bb++; if (bb>=m) bb=3;
    }
}

void solve() {
    int gr_m=m-1-!(m%2);
    int gr_n=n-1-!(n%2);
    for (int i=0; i<gr_n; ++i) {
        for (int j=i%2; j<gr_m; j+=2) mat[i][j]=1;
    }
    for (int i=gr_n; i<n; ++i) {
        for (int j=0; j<m; ++j) mat[i][j]=1;
    }
}

void ispis() {
    int sol=0;
    for (int j=0; j<m; ++j) stup[j]=0;
    for (int i=0; i<n; ++i) {
        red[i]=0;
        for (int j=0; j<m; ++j) {
            red[i]+=!mat[i][j];
            stup[j]+=mat[i][j];
        }
        sol+=red[i] > m/2;
    }
    for (int j=0; j<m; ++j) sol+=stup[j] > n/2;

    printf("%d\n", sol);
    for (int i=0; i<n; ++i) {
        for (int j=0; j<m; ++j) printf("%c", mat[i][j] ? '-' : '+');
        printf("\n");
    }
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf("%d %d", &n, &m);

        fl=n<m;
        if (fl) swap(n, m);

        if (m<=2) mali_stup();
        else if (n==4) poseban_4();
        else if (m<=4) pos_stup();
        else if (m<=6) poseb56();
        else if (m==8) poseb8();
        else solve();

        if (fl) rotiraj();

        ispis();
        reset();
        if (fl) {
            swap(n, m);
            reset();
        }
    }
    return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:103:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  103 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
stones.cpp:105:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  105 |         scanf("%d %d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Correct 4 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 2156 KB Output is correct
2 Correct 63 ms 8172 KB Output is correct
3 Correct 72 ms 8832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 2412 KB Wrong answer in test 8 8: 11 < 12
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Correct 4 ms 748 KB Output is correct
5 Correct 67 ms 2156 KB Output is correct
6 Correct 63 ms 8172 KB Output is correct
7 Correct 72 ms 8832 KB Output is correct
8 Incorrect 78 ms 2412 KB Wrong answer in test 8 8: 11 < 12
9 Halted 0 ms 0 KB -