답안 #402683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402683 2021-05-12T08:48:05 Z keta_tsimakuridze Red-blue table (IZhO19_stones) C++14
32 / 100
301 ms 1768 KB
#include<bits/stdc++.h>
#define f first
//#define int long long
#define s second
#define pii pair<int,int>
using namespace std;
const int N=1e3+5,mod=1e9+7;
int t,n,m,red[N];
char a[N][N];
set<pii> s;
 main(){
	// t=1;
	cin >> t;
	while(t--){
		cin>>n>>m;
		for(int i=1;i<=m;i++) red[i] = 0;
		int B = m;
		int ans = B,cnt=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++) a[i][j]='-';
		}
		for(int i=1;i<=n;i++){
			s.clear();
			int c  = 0,all = (i-1)*(m/2+1);
			for(int j=1;j<=m;j++)   {
				if(red[j] >= (n+1)/2) c++;
			}
			int C=m-c;
			for(int j=1;j<=m;j++) {
				if(c)  {
				red[j] = min(all,i-1);
				all-=min(all,i-1);
				c--; }
				else {
				 red[j] = all/C; if(all%C)all--, red[j]++; } 
				s.insert({red[j],j});
			}
			for(int j=1;j<=m/2+1;j++) {
				pii c = *--s.end();
				if(c.f>=(n+1)/2) red[c.s]++,s.erase(c);
				else {
				pii c = *s.begin(); 
				s.erase(c);
				if(c.f+1==(n+1)/2) B--; red[c.s]++; }
				
			}
			if(i+B>ans) ans=i+B,cnt=i;
		}
		cout<<ans<<endl;
		s.clear();
		for(int i=1;i<=m;i++) red[i] = 0;
		for(int i=1;i<=cnt;i++){
			s.clear();
			int c  = 0,all = (i-1)*(m/2+1);
			for(int j=1;j<=m;j++)   {
				if(red[j] >= (n+1)/2) c++;
			}
			int C=m-c;
			for(int j=1;j<=m;j++) {
				if(c)  {
				red[j] = min(all,i-1);
				all-=min(all,i-1);
				c--; }
				else {
				 red[j] = all/C; if(all%C)all--, red[j]++; } 
				s.insert({red[j],j});
			}
			for(int j=1;j<=m/2+1;j++) {
				pii c = *--s.end();
				if(c.f>=(n+1)/2) red[c.s]++,a[i][c.s] = '+',s.erase(c);
				else {
				pii c = *s.begin(); 
				s.erase(c);
				a[i][c.s] = '+';
				red[c.s]++;	}
				
			}
		}	
		for(int i=1;i<=n;i++){
		
		for(int j=1;j<=m;j++) 
		cout<<a[i][j];
		cout<<endl;
		}
	}
}

Compilation message

stones.cpp:11:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 |  main(){
      |  ^~~~
stones.cpp: In function 'int main()':
stones.cpp:44:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   44 |     if(c.f+1==(n+1)/2) B--; red[c.s]++; }
      |     ^~
stones.cpp:44:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   44 |     if(c.f+1==(n+1)/2) B--; red[c.s]++; }
      |                             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 372 KB in the table A+B is not equal to 17
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 13 ms 372 KB in the table A+B is not equal to 17
# 결과 실행 시간 메모리 Grader output
1 Incorrect 301 ms 1368 KB in the table A+B is not equal to 114
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 1444 KB Output is correct
2 Correct 253 ms 1768 KB Output is correct
3 Correct 244 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 13 ms 372 KB in the table A+B is not equal to 17