Submission #282862

# Submission time Handle Problem Language Result Execution time Memory
282862 2020-08-25T05:29:06 Z arnold518 None (JOI15_walls) C++14
10 / 100
3000 ms 3880 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;

int N, M;
pii A[MAXN+10];
int B[MAXN+10];

int main()
{
	scanf("%d%d", &N, &M);
	for(int i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
	//M++; B[1]=0;
	for(int i=1; i<=M; i++) scanf("%d", &B[i]);

	M=unique(B+1, B+M+1)-B-1;
	vector<int> V;
	V.push_back(B[1]);
	for(int i=2; i<M; i++)
	{
		if(B[i-1]<B[i] && B[i+1]<B[i]) V.push_back(B[i]);
		else if(B[i-1]>B[i] && B[i+1]>B[i]) V.push_back(B[i]);
	}
	V.push_back(B[M]);

	for(int i=0; i<V.size(); i++) B[i+1]=V[i];
	M=V.size();
	
	for(int j=1; j<=N; j++)
	{
		ll ans=0;
		for(int i=1; i<=M; i++)
		{
			if(A[j].first<=B[i] && B[i]<=A[j].second) continue;
			else if(B[i]<A[j].first)
			{
				int t=A[j].first-B[i];
				ans+=t; A[j].first-=t; A[j].second-=t;
			}
			else if(B[i]>A[j].second)
			{
				int t=B[i]-A[j].second;
				ans+=t; A[j].first+=t; A[j].second+=t;
			}
		}
		printf("%lld\n", ans);
	}
}

Compilation message

walls.cpp: In function 'int main()':
walls.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=0; i<V.size(); i++) B[i+1]=V[i];
      |               ~^~~~~~~~~
walls.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
walls.cpp:17:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  for(int i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
walls.cpp:19:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  for(int i=1; i<=M; i++) scanf("%d", &B[i]);
      |                          ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 45 ms 3824 KB Output is correct
3 Correct 45 ms 3856 KB Output is correct
4 Correct 45 ms 3880 KB Output is correct
5 Correct 47 ms 3824 KB Output is correct
6 Correct 44 ms 3824 KB Output is correct
7 Correct 32 ms 2680 KB Output is correct
8 Correct 38 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1265 ms 1092 KB Output is correct
2 Execution timed out 3054 ms 2416 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 45 ms 3824 KB Output is correct
3 Correct 45 ms 3856 KB Output is correct
4 Correct 45 ms 3880 KB Output is correct
5 Correct 47 ms 3824 KB Output is correct
6 Correct 44 ms 3824 KB Output is correct
7 Correct 32 ms 2680 KB Output is correct
8 Correct 38 ms 2680 KB Output is correct
9 Correct 1265 ms 1092 KB Output is correct
10 Execution timed out 3054 ms 2416 KB Time limit exceeded
11 Halted 0 ms 0 KB -