답안 #370380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370380 2021-02-23T22:07:59 Z nicolaalexandra Red-blue table (IZhO19_stones) C++14
100 / 100
881 ms 9404 KB
#include <bits/stdc++.h>
#define DIM 1010
using namespace std;

int t,n,m,i,j;
int a[DIM][DIM],aux[DIM][DIM],lin[DIM],col[DIM];
vector <pair<int,int> > v;

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>t;
    for (;t--;){
        memset (a,0,sizeof a);
        memset (aux,0,sizeof aux);
        memset (lin,0,sizeof lin);
        memset (col,0,sizeof col);

        cin>>n>>m;

        int swapped = 0;
        if (n > m){
            swap (n,m);
            swapped = 1;
        }

        int sol = m;
        for (i=1;i<=n;i++){
            /// verific daca am suficiente coloane libere ca sa formez o linie buna
            /// nu vreau sa stric coloanele care sunt deja toate ok
            v.clear();
            for (j=1;j<=m;j++){
                if (col[j] + 1 <= (n-1)/2)
                    v.push_back(make_pair(col[j],j));
            }

            if (v.size() <= m/2) /// nu mai am cum sa formez nicio linie
                break;

            sol++;
            /// o sa pun unuri pe coloanele unde am cei mai putini
            sort (v.begin(),v.end());
            for (j=0;j<=m/2;j++){
                int poz = v[j].second;
                col[poz]++;
                lin[i]++;
                a[i][poz] = 1;
            }
        }

        if (swapped){
            for (i=1;i<=n;i++)
                for (j=1;j<=m;j++)
                    aux[m-j+1][i] = a[i][j];

            swap (n,m);
            for (i=1;i<=n;i++)
                for (j=1;j<=m;j++)
                    a[i][j] = 1 - aux[i][j];
        }

        cout<<sol<<"\n";
        for (i=1;i<=n;i++,cout<<"\n")
            for (j=1;j<=m;j++){
                if (a[i][j])
                    cout<<"+";
                else cout<<"-";
            }

    }

    return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:39:26: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |             if (v.size() <= m/2) /// nu mai am cum sa formez nicio linie
      |                 ~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8300 KB Output is correct
2 Correct 20 ms 8300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 8428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8300 KB Output is correct
2 Correct 20 ms 8300 KB Output is correct
3 Correct 264 ms 8428 KB Output is correct
4 Correct 463 ms 8388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 9404 KB Output is correct
2 Correct 71 ms 9196 KB Output is correct
3 Correct 75 ms 9156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 9324 KB Output is correct
2 Correct 67 ms 9196 KB Output is correct
3 Correct 60 ms 9068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8300 KB Output is correct
2 Correct 20 ms 8300 KB Output is correct
3 Correct 264 ms 8428 KB Output is correct
4 Correct 463 ms 8388 KB Output is correct
5 Correct 459 ms 9404 KB Output is correct
6 Correct 71 ms 9196 KB Output is correct
7 Correct 75 ms 9156 KB Output is correct
8 Correct 201 ms 9324 KB Output is correct
9 Correct 67 ms 9196 KB Output is correct
10 Correct 60 ms 9068 KB Output is correct
11 Correct 881 ms 8804 KB Output is correct
12 Correct 64 ms 9068 KB Output is correct
13 Correct 84 ms 9196 KB Output is correct
14 Correct 52 ms 8940 KB Output is correct
15 Correct 86 ms 9324 KB Output is correct
16 Correct 58 ms 9068 KB Output is correct
17 Correct 29 ms 8684 KB Output is correct