Submission #318714

# Submission time Handle Problem Language Result Execution time Memory
318714 2020-11-03T01:02:03 Z Marlov Vođe (COCI17_vode) C++14
120 / 120
1460 ms 192868 KB
/*
Code by @marlov       
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <iterator>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;

#define maxV 5005

int N,M,K;
int arr[maxV];
int dp[maxV][maxV];
int psum[maxV][maxV];
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>N>>M>>K;
	for(int i=0;i<N;i++){
		fill(dp[i],dp[i]+maxV,-1);
	}
	for(int i=0;i<N;i++){
		cin>>arr[i];
		dp[i][M]=1-arr[i];
		psum[i][M]=1-arr[i];
	}
	for(int j=M-1;j>=0;j--){
		for(int i=0;i<N;i++){
			int pvs=psum[(i+1)%N][j+1]-psum[(i+1)%N][min(M+1,j+1+K)];
			if(pvs==0){
				dp[i][j]=0;
			}else if(pvs==K||(j>M-K&&pvs==M-j)){
				dp[i][j]=1;
			}else{
				dp[i][j]=arr[(i+1)%N];
			}
			//cout<<dp[i][j]<<" ";
		}
		//cout<<'\n';
		for(int i=0;i<N;i++){
			psum[i][j]=dp[i][j]+psum[i][j+1];
		}
	}
	for(int i=0;i<N;i++){
		cout<<dp[(i+N-1)%N][0]<<" ";
	}
    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1,n=0?)
	* do smth instead of nothing and stay organized
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 2156 KB Output is correct
3 Correct 2 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4716 KB Output is correct
2 Correct 2 ms 2924 KB Output is correct
3 Correct 4 ms 4844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5996 KB Output is correct
2 Correct 4 ms 5612 KB Output is correct
3 Correct 5 ms 6252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8300 KB Output is correct
2 Correct 8 ms 9836 KB Output is correct
3 Correct 8 ms 9452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12140 KB Output is correct
2 Correct 9 ms 11628 KB Output is correct
3 Correct 9 ms 11028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10604 KB Output is correct
2 Correct 9 ms 10988 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 54372 KB Output is correct
2 Correct 207 ms 56424 KB Output is correct
3 Correct 1210 ms 189212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 429 ms 87392 KB Output is correct
2 Correct 1146 ms 188936 KB Output is correct
3 Correct 442 ms 95716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1404 ms 190308 KB Output is correct
2 Correct 7 ms 4844 KB Output is correct
3 Correct 4 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1392 ms 191800 KB Output is correct
2 Correct 1161 ms 192484 KB Output is correct
3 Correct 1460 ms 192868 KB Output is correct