제출 #114405

#제출 시각아이디문제언어결과실행 시간메모리
114405sebinkimWorld of Tank (innopolis2018_final_E)C++14
100 / 100
485 ms66400 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

bool B[2020202][2];
vector <int> X;
int D[2020202][2];
int dp[2020202][2], C[2020202][2];

int n, m1, m2, t;

void print()
{
	vector <int> V1;
	vector <pii> V2;
	
	int i, j, l, r, y;
	
	y = 0;
	
	for(i=0; i<n; i++){
		if(C[i][y]){
			y = 1 - y;
			V1.push_back(X[i]);
		}
		
		l = dp[i][y] - X[i + 1] + X[i]; r = dp[i][y];
		if(l >= 0) continue;
		for(j=-(l+1)/t; j>=0 && -j*t <= r; j--){
			V2.emplace_back(X[i] + (r + j*t), y);
		}
	}
	
	sort(V2.begin(), V2.end());
	
	printf("Yes\n");
	
	printf("%d\n", V1.size());
	for(int &t: V1) printf("%d ", t); printf("\n");
	
	printf("%d\n", V2.size());
	for(pii &t: V2) printf("%d %d\n", t.first, t.second + 1);
}

int main()
{
	int i, j, k, x;
	
	scanf("%d%d%d%d", &n, &m1, &m2, &t);
	
	for(i=1; i<=m1; i++){
		scanf("%d", D[i]);
		X.push_back(D[i][0]);
		X.push_back(D[i][0] + 1);
	}
	
	for(i=1; i<=m2; i++){
		scanf("%d", D[i] + 1);
		X.push_back(D[i][1]);
		X.push_back(D[i][1] + 1);
	}
	
	X.push_back(0); X.push_back(n + 1);
	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());
	
	for(i=1; i<=m1; i++){
		k = lower_bound(X.begin(), X.end(), D[i][0]) - X.begin();
		B[k][0] = 1;
	}
	
	for(i=1; i<=m2; i++){
		k = lower_bound(X.begin(), X.end(), D[i][1]) - X.begin();
		B[k][1] = 1;
	}
	
	n = X.size() - 1;
	
	dp[n][0] = 1e9;
	dp[n][1] = 1e9;
	
	for(i=n-1; i>=0; i--){
		for(j=0; j<2; j++){
			if(B[i][j]){
				dp[i][j] = min(-1, dp[i + 1][j] - t + 1);
				
				if(!B[i][1 - j]){
					if(dp[i + 1][1 - j] >= -1 && dp[i][j] < min(-1, dp[i + 1][1 - j] - t + 1)){
						C[i][j] = 1;
						dp[i][j] = min(-1, dp[i + 1][1 - j] - t + 1);
					}
				}
			}
			else{
				dp[i][j] = dp[i + 1][j] + X[i + 1] - X[i];
				
				if(!B[i][1 - j]){
					if(dp[i + 1][1 - j] >= -X[i + 1] + X[i] && dp[i][j] < dp[i + 1][1 - j] + X[i + 1] - X[i]){
						C[i][j] = 1;
						dp[i][j] = dp[i + 1][1 - j] + X[i + 1] - X[i];
					}
				}
			}
		}
	}
	
	if(dp[0][0] >= t) print();
	else printf("No\n");
	
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

E.cpp: In function 'void print()':
E.cpp:40:26: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", V1.size());
                 ~~~~~~~~~^
E.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(int &t: V1) printf("%d ", t); printf("\n");
  ^~~
E.cpp:41:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(int &t: V1) printf("%d ", t); printf("\n");
                                    ^~~~~~
E.cpp:43:26: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", V2.size());
                 ~~~~~~~~~^
E.cpp: In function 'int main()':
E.cpp:49:15: warning: unused variable 'x' [-Wunused-variable]
  int i, j, k, x;
               ^
E.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &n, &m1, &m2, &t);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", D[i]);
   ~~~~~^~~~~~~~~~~~
E.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", D[i] + 1);
   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...