답안 #336336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336336 2020-12-15T05:07:37 Z Kerim Red-blue table (IZhO19_stones) C++17
100 / 100
100 ms 2284 KB
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=1e3+4;
char res[N][N];
int main(){
    //freopen("file.in", "r", stdin);
    //freopen("grid.in", "w", stdout);
    int t=1;
    scanf("%d",&t);
    while(t--){
    	int n,m;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				res[i][j]='-';
		int ans=m,x=(m-1)/2,y=n/2+1,a=0,b=m;
		for(int A=1;A<=n;A++){
			if(y-(n-A)>0){
				int B=min(m,(A*x)/(y-(n-A)));
				if(umax(ans,A+B))
					a=A,b=B;
			//	printf("%d %d\n",A,B);
			}
			else{
				ans=A+m;
				a=A;b=m;
			}	
		}
		printf("%d\n",ans);
		priority_queue<PII>q;
		for(int i=1;i<=b;i++)
			q.push(mp((n-1)/2,i));
		for(int i=b+1;i<=m;i++)
			q.push(mp(n,i));
		vector<PII>tmp;
		for(int i=1;i<=a;i++){
			tmp.clear();
			for(int j=0;j<=m/2;j++){
				assert(!q.empty());
				PII nd=q.top();q.pop();
				assert(nd.ff>0);
				res[i][nd.ss]='+';
				tmp.pb(mp(nd.ff-1,nd.ss));
			}
			tr(it,tmp)
				q.push(*it);
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++)
				printf("%c",res[i][j]);
			puts("");	
		}
    }
	return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
stones.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |   scanf("%d%d",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 1516 KB Output is correct
2 Correct 100 ms 1980 KB Output is correct
3 Correct 87 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 1652 KB Output is correct
2 Correct 78 ms 1900 KB Output is correct
3 Correct 71 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 93 ms 1516 KB Output is correct
6 Correct 100 ms 1980 KB Output is correct
7 Correct 87 ms 2156 KB Output is correct
8 Correct 93 ms 1652 KB Output is correct
9 Correct 78 ms 1900 KB Output is correct
10 Correct 71 ms 1644 KB Output is correct
11 Correct 20 ms 620 KB Output is correct
12 Correct 88 ms 1936 KB Output is correct
13 Correct 93 ms 2028 KB Output is correct
14 Correct 60 ms 1772 KB Output is correct
15 Correct 96 ms 2284 KB Output is correct
16 Correct 74 ms 1900 KB Output is correct
17 Correct 32 ms 1336 KB Output is correct