Submission #236540

# Submission time Handle Problem Language Result Execution time Memory
236540 2020-06-02T12:54:07 Z kshitij_sodani Red-blue table (IZhO19_stones) C++17
100 / 100
115 ms 6140 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(i+bb>=ma){
					ma=i+bb;
					aa={i,bb};
				}*/
			}
			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;
			int vis[1001];
			for(int i=0;i<1001;i++){
				vis[i]=0;
			}
			int cot[1001];
			for(int i=0;i<1001;i++){
				cot[i]=0;
			}
			for(int i=0;i<aa.a;i++){
				vector<int> kk;
				for(int j=0;j<l;j++){
					if(j<le){
						it[i][j]=1;
						continue;
					}
					if(freq[ind].size()==0){
						ind+=1;
					}
				/*	if(ind>=(m-1)/2){
						while(true){
							continue;
						}
					}*/
					it[i][freq[ind].back()]=1;
				//	cout<<i<<":"<<freq[ind].back()<<endl;
					int xx=freq[ind].back();
					kk.pb(xx);
				
					vis[xx]=1;
					cot[xx]+=1;
				/*	if(ind>=(n-1)/2){
						while(true){
							continue;
						}
					}*/
					freq[ind+1].push_front(xx);
					freq[ind].pop_back();
				}
				for(auto j:kk){
					vis[j]=0;
				}
			}
			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;
		//	cout<<coo+aa.a<<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;
        ^~
stones.cpp:70:8: warning: variable 'vis' set but not used [-Wunused-but-set-variable]
    int vis[1001];
        ^~~
# 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 37 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 37 ms 1024 KB Output is correct
4 Correct 63 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 2040 KB Output is correct
2 Correct 41 ms 4608 KB Output is correct
3 Correct 39 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 2040 KB Output is correct
2 Correct 38 ms 3964 KB Output is correct
3 Correct 36 ms 3088 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 37 ms 1024 KB Output is correct
4 Correct 63 ms 1144 KB Output is correct
5 Correct 115 ms 2040 KB Output is correct
6 Correct 41 ms 4608 KB Output is correct
7 Correct 39 ms 4728 KB Output is correct
8 Correct 74 ms 2040 KB Output is correct
9 Correct 38 ms 3964 KB Output is correct
10 Correct 36 ms 3088 KB Output is correct
11 Correct 113 ms 1272 KB Output is correct
12 Correct 41 ms 3584 KB Output is correct
13 Correct 42 ms 3080 KB Output is correct
14 Correct 32 ms 2376 KB Output is correct
15 Correct 47 ms 6140 KB Output is correct
16 Correct 34 ms 4736 KB Output is correct
17 Correct 20 ms 2688 KB Output is correct