답안 #199830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199830 2020-02-03T14:46:42 Z path Sajam (COCI18_sajam) C++14
90 / 90
45 ms 4216 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f first
#define s second
#define pb push_back
const int N=1e3+5;
int n,k,a[N][N],c[N],r[N],t,tmp;
char ch;
pair<int,int> mr,mc;
priority_queue< pair<int,int> > q[2];
int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
        cin>>ch;
        a[i][j]=(ch=='o');
        if(a[i][j]) t++;
    }
    for(int i=0;i<n;i++){
        tmp=0;
        for(int j=0;j<n;j++)
            if(a[i][j]) tmp++;
        r[i]=tmp;
    }
    for(int j=0;j<n;j++){
        tmp=0;
        for(int i=0;i<n;i++)
            if(a[i][j]) tmp++;
        c[j]=tmp;

    }

    for(int i=0;i<2*n && t>k ;i++){
        //cout<<t<<'\n';
        mr= {r[0],0}; mc={c[0],0};
        for(int j=0;j<n;j++){
            if(r[j]>mr.f)
                mr={r[j],j};
            if(c[j]>mc.f)
                mc={c[j],j};
        }
        if(mr.f>mc.f){
            int row=mr.s;
            for(int j=0;j<n;j++){
                if(a[row][j]){
                    r[row]--;
                    c[j]--;
                    t--;
                }
                else{
                    r[row]++;
                    c[j]++;
                    t++;
                }
                a[row][j]=(!a[row][j]);
            }
        }
        else{
            int col=mc.s;
            for(int j=0;j<n;j++){
                if(a[j][col]){
                    r[j]--;
                    c[col]--;
                    t--;
                }
                else{
                    r[j]++;
                    c[col]++;
                    t++;
                }
                a[j][col]=(!a[j][col]);
            }
        }
    }
    if(t<=k)
        cout<<"DA\n";
    else
        cout<<"NE\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 11 ms 2040 KB Output is correct
3 Correct 14 ms 2408 KB Output is correct
4 Correct 32 ms 3960 KB Output is correct
5 Correct 14 ms 2424 KB Output is correct
6 Correct 8 ms 1656 KB Output is correct
7 Correct 15 ms 2296 KB Output is correct
8 Correct 41 ms 4088 KB Output is correct
9 Correct 7 ms 1272 KB Output is correct
10 Correct 42 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3320 KB Output is correct
2 Correct 27 ms 3624 KB Output is correct
3 Correct 20 ms 3064 KB Output is correct
4 Correct 22 ms 2808 KB Output is correct
5 Correct 30 ms 3960 KB Output is correct
6 Correct 17 ms 2424 KB Output is correct
7 Correct 24 ms 3196 KB Output is correct
8 Correct 27 ms 3448 KB Output is correct
9 Correct 12 ms 1912 KB Output is correct
10 Correct 45 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 3704 KB Output is correct
2 Correct 35 ms 3704 KB Output is correct
3 Correct 18 ms 2936 KB Output is correct
4 Correct 22 ms 3192 KB Output is correct
5 Correct 24 ms 3320 KB Output is correct
6 Correct 40 ms 4088 KB Output is correct
7 Correct 13 ms 2168 KB Output is correct
8 Correct 24 ms 3192 KB Output is correct
9 Correct 35 ms 3448 KB Output is correct
10 Correct 44 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2936 KB Output is correct
2 Correct 20 ms 2936 KB Output is correct
3 Correct 35 ms 4216 KB Output is correct
4 Correct 14 ms 2424 KB Output is correct
5 Correct 18 ms 2936 KB Output is correct
6 Correct 42 ms 4088 KB Output is correct
7 Correct 18 ms 2424 KB Output is correct
8 Correct 17 ms 2548 KB Output is correct
9 Correct 19 ms 2552 KB Output is correct
10 Correct 18 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 4216 KB Output is correct
2 Correct 34 ms 4216 KB Output is correct
3 Correct 32 ms 3960 KB Output is correct
4 Correct 25 ms 3320 KB Output is correct
5 Correct 27 ms 3192 KB Output is correct
6 Correct 25 ms 3320 KB Output is correct
7 Correct 16 ms 2424 KB Output is correct
8 Correct 34 ms 3832 KB Output is correct
9 Correct 23 ms 2808 KB Output is correct
10 Correct 43 ms 4088 KB Output is correct