Submission #236542

# Submission time Handle Problem Language Result Execution time Memory
236542 2020-06-02T12:55:09 Z kshitij_sodani Red-blue table (IZhO19_stones) C++17
100 / 100
121 ms 6008 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n,m,t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>t;
	while(t--){
		cin>>n>>m;
		
			int k=(n+2)/2;
			int l=(m+2)/2;
			int ma=-1;
			pair<int,int> aa={-1,-1};
			int bb=m;
			for(int i=0;i<=n;i++){
				for(int j=0;j<=m;j++){
					if(i*l+j*k<=n*m){
						int le2=m-j;
						int st=1;
						if(l>le2){
							if((l-le2)*i>(n-k)*(j)){
								st=0;
							}
						}
						if(st){
							if(i+j>ma){
								ma=i+j;
								aa={i,j};
							}
						}
					}
				}

			}
			if(aa.b<0){
				while(true){
					continue;
				}
			}
			int it[n][m];
			for(int i=0;i<n;i++){
				for(int j=0;j<m;j++){
					it[i][j]=0;
				}
			}
			int le=m-aa.b;
			/*if(ma==34){
				return 0;
			}*/
			//cout<<ma<<endl;
			deque<int> freq[1001];
			int ind=0;
			for(int i=0;i<1001;i++){
				freq[i].clear();
			}
			for(int i=le;i<m;i++){
				freq[0].pb(i);
			}
			//(m-le)
			//cout<<aa.a<<","<<aa.b<<endl;
	
			for(int i=0;i<aa.a;i++){
				for(int j=0;j<l;j++){
					if(j<le){
						it[i][j]=1;
						continue;
					}
					if(freq[ind].size()==0){
						ind+=1;
					}
	
					it[i][freq[ind].back()]=1;
				//	cout<<i<<":"<<freq[ind].back()<<endl;
					int xx=freq[ind].back();


					freq[ind+1].push_front(xx);
					freq[ind].pop_back();
				}

			}
			int coo=0;
			for(int i=0;i<m;i++){
				int co=0;
				for(int j=0;j<n;j++){
					if(it[j][i]==0){
						co+=1;
					}
				}
				if(co>=k){
					coo+=1;

				}
			
			}
		
			cout<<ma<<endl;
			for(int i=0;i<n;i++){
				for(int j=0;j<m;j++){
					if(it[i][j]==1){
						cout<<"+";
					}
					else{
						cout<<"-";
					}
				}
				cout<<endl;
			}


	
		
	}


	return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:20:8: warning: unused variable 'bb' [-Wunused-variable]
    int bb=m;
        ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 35 ms 1024 KB Output is correct
4 Correct 54 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 2052 KB Output is correct
2 Correct 44 ms 4468 KB Output is correct
3 Correct 41 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 2100 KB Output is correct
2 Correct 37 ms 3872 KB Output is correct
3 Correct 42 ms 3068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 35 ms 1024 KB Output is correct
4 Correct 54 ms 1024 KB Output is correct
5 Correct 121 ms 2052 KB Output is correct
6 Correct 44 ms 4468 KB Output is correct
7 Correct 41 ms 4728 KB Output is correct
8 Correct 73 ms 2100 KB Output is correct
9 Correct 37 ms 3872 KB Output is correct
10 Correct 42 ms 3068 KB Output is correct
11 Correct 102 ms 1272 KB Output is correct
12 Correct 39 ms 3596 KB Output is correct
13 Correct 40 ms 3100 KB Output is correct
14 Correct 33 ms 2364 KB Output is correct
15 Correct 44 ms 6008 KB Output is correct
16 Correct 40 ms 4728 KB Output is correct
17 Correct 19 ms 2688 KB Output is correct