Submission #683837

# Submission time Handle Problem Language Result Execution time Memory
683837 2023-01-19T12:38:29 Z dostigator Red-blue table (IZhO19_stones) C++17
27 / 100
145 ms 1336 KB
//izho gold
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
#define Y second
#define X first
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll INF=1e18;
const int inf=1e9;
const int N=2e5+505;
const int M=1e3+10;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int n,m;

void solve(){
	cin>>n>>m;
	if(n>m && m==1){
		cout<<n<<endl;
		for(int i=1; i<=n; ++i){
			cout<<'+';
			cout<<endl;
		}return;
	}
	if(n<=m || 1){
		int nd=m/2+1;
		char matrix[n+1][m+1];
		int l=1;
		vt<pair<int,int>>lst;
		for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j)matrix[i][j]='-';
		lst.pb({m,0});
		for(int i=1; i<=n; ++i){
		//	cout<<l<<endl;
			if(l+nd-1<=m) {
				//cout<<"YES\n";
				for(int j=l; j<=l+nd-1; ++j) matrix[i][j]='+';
				l+=2;
				if(l>m) l%=m;
			}
			else if(l+nd-1>m){
				for(int j=l; j<=m; ++j) matrix[i][j]='+';
				l+=nd;
				--l;
				l%=m;
				for(int j=1; j<=l; ++j)matrix[i][j]='+';
				l+=2;
				if(l>m)l%=m;
			}int cnt=i;
			int mn=inf;
			for(int j=1; j<=m; ++j){
				int cur=0;
				for(int x=1; x<=n; ++x)if(matrix[x][j]=='-')++cur;
				if(cur>=n/2+1)++cnt;
			}lst.pb({cnt,i});
		}l=1;
		sort(all(lst));
	//	cout<<lst.back().Y<<endl;
		for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j)matrix[i][j]='-';
		for(int i=1; i<=lst.back().Y; ++i){
			if(l+nd-1<=m) {
				for(int j=l; j<=l+nd-1; ++j) matrix[i][j]='+';
				l+=2;
				if(l>m) l%=m;
			}
			else if(l+nd-1>m){
				for(int j=l; j<=m; ++j) matrix[i][j]='+';
				l+=nd;
				--l;
				l%=m;
				for(int j=1; j<=l; ++j)matrix[i][j]='+';
				l+=2;
				if(l>m)l%=m;
			}
		}cout<<lst.back().X<<endl;
		for(int i=1; i<=n; ++i){
			for(int j=1; j<=m; ++j){
				cout<<matrix[i][j];
			}cout<<endl;
		}return;
	}/*int nd=n/2+1;
		char matrix[n+1][m+1];
		int l=1;
		vt<pair<int,int>>lst;
		for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j)matrix[i][j]='-';
		lst.pb({m,0});
		for(int j=1; j<=m; ++j){
			if(l+nd-1<=n) {
				for(int i=l; i<=l+nd-1; ++i) matrix[i][j]='+';
				l+=2;
				if(l>n) l%=n;
			}
			if(l+nd-1>n){
				for(int i=l; i<=n; ++i) matrix[i][j]='+';
				l+=nd;
				--l;
				l%=n;
				for(int i=1; i<=l; ++i)matrix[i][j]='+';
				l+=2;
				if(l>n)l%=n;
			}int cnt=j;
			int mn=inf;
			for(int i=1; i<=n; ++i){
				int cur=0;
				for(int x=1; x<=m; ++x)if(matrix[j][x]=='-')++cur;
				if(cur>=n/2+1)++cnt;
			}lst.pb({cnt,i});
		}l=1;
		sort(all(lst));
		for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j)matrix[i][j]='-';
		for(int i=1; i<=lst.back().Y; ++i){
			if(l+nd-1<=m) {
				for(int j=l; j<=l+nd-1; ++j) matrix[i][j]='+';
				l+=2;
				if(l>m) l%=m;
			}
			if(l+nd-1>m){
				for(int j=l; j<=m; ++j) matrix[i][j]='+';
				l+=nd;
				--l;
				l%=m;
				for(int j=1; j<=l; ++j)matrix[i][j]='+';
				l+=2;
				if(l>m)l%=m;
			}
		}cout<<lst.back().X<<endl;
		for(int i=1; i<=n; ++i){
			for(int j=1; j<=m; ++j){
				cout<<matrix[i][j];
			}cout<<endl;
		}*/
}

int main(){
	//srand(time(0));
	//freopen("hotel.in","r",stdin);
	//freopen("hotel.out","w",stdout);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tt=1,lolol=0;
	cin>>tt;
	while(tt--) {
		//cout<<"Case "<<++lolol<<": ";
		solve();
	}
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:57:8: warning: unused variable 'mn' [-Wunused-variable]
   57 |    int mn=inf;
      |        ^~
stones.cpp: In function 'int main()':
stones.cpp:146:11: warning: unused variable 'lolol' [-Wunused-variable]
  146 |  int tt=1,lolol=0;
      |           ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 224 KB Output is correct
4 Incorrect 3 ms 356 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 1336 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 145 ms 1228 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 224 KB Output is correct
4 Incorrect 3 ms 356 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -