답안 #369207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
369207 2021-02-20T22:38:57 Z Ahmad_Hasan Vođe (COCI17_vode) C++17
120 / 120
1479 ms 283244 KB
#include <bits/stdc++.h>
/**
     ||||||||||       |||||     |||||    ||||||||||
    |||||||||||||     |||||     |||||  |||||
   ||||     ||||||    |||||     |||||  |||||
  |||||||||||||||||   |||||||||||||||    ||||||||||
 |||||||||||||||||||  |||||||||||||||           |||||
 |||||         |||||  |||||     |||||           |||||
 |||||         |||||  |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;



int32_t main()
{
    /**freopen("movie.in","r",stdin);
    freopen("movie.out","w",stdout);*/
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);


    int n,m,k;
    cin>>n>>m>>k;

    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int dp[n][m+5];

    for(int i=0;i<n;i++){
        dp[i][m]=0;
        dp[i][0]=-1;
    }

    int cntr[n][m+5][2];
    memset(cntr,0,sizeof(cntr));
    for(int i=0;i<n;i++)
        cntr[i][m][0]=1;

    for(int j=m-1;j>=0;j--){
        for(int i=n-1;i>=0;i--){

            if(j==0){
                if(cntr[i][j+1][1])
                    dp[i][j]=1;
                else
                    dp[i][j]=0;
            }
            else{
                if(v[i]==v[(i+1)%n]){
                    if(cntr[(i+1)%n][j+1][1])
                        dp[i][j]=1;
                    else
                        dp[i][j]=0;
                }
                else{
                    if(cntr[(i+1)%n][j+1][1])
                        dp[i][j]=0;
                    else
                        dp[i][j]=1;
                }
            }
            cntr[i][j][0]=cntr[i][j+1][0];
            cntr[i][j][1]=cntr[i][j+1][1];
            cntr[i][j][dp[i][j]]++;
            if(j+k<=m){
                cntr[i][j][dp[i][j+k]]--;

            }
            ///cout<<i<<' '<<j<<' '<<cntr[i][j][0]<<'\n';


            /**
            for(int z=1;z<=k;z++){
                if(z+j<=m){
                    if(j==0){
                        dp[i][j]=max(dp[i][j],dp[i][z]);
                    }
                    else{
                        if(v[i]==v[(i+1)%n])
                            dp[i][j]=max(dp[i][j],dp[(i+1)%n][j+z]);
                        else{
                            if(dp[i][j]==-2)
                                dp[i][j]=2;
                            dp[i][j]=min(dp[i][j],1-dp[(i+1)%n][j+z]);
                        }
                    }
                }

            }*/
        }
    }
/**
    for(int i=0;i<n;i++){
        cout<<'#';
        for(int j=0;j<=m;j++){
            cout<<dp[i][j]<<' ';
        }
        cout<<'\n';
    }
    for(int i=0;i<n;i++){
        cout<<'#';
        for(int j=0;j<=m;j++){
            cout<<cntr[i][j][0]<<'&'<<cntr[i][j][1]<<' ';
        }
        cout<<'\n';
    }
*/

    for(int i=0;i<n;i++)
        cout<<((dp[i][0]==1)?v[i]:!v[i])<<' ';



    return 0;
}



/**
6 20 5
1 0 0 1 1 0


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 2 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1772 KB Output is correct
2 Correct 3 ms 2028 KB Output is correct
3 Correct 3 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2796 KB Output is correct
2 Correct 5 ms 2540 KB Output is correct
3 Correct 3 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2540 KB Output is correct
2 Correct 6 ms 2668 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 35308 KB Output is correct
2 Correct 117 ms 39660 KB Output is correct
3 Correct 1355 ms 257996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 395 ms 84332 KB Output is correct
2 Correct 1163 ms 230484 KB Output is correct
3 Correct 402 ms 89324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1479 ms 283244 KB Output is correct
2 Correct 13 ms 6636 KB Output is correct
3 Correct 5 ms 4076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1404 ms 281324 KB Output is correct
2 Correct 1231 ms 250980 KB Output is correct
3 Correct 893 ms 278760 KB Output is correct