답안 #757491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757491 2023-06-13T09:01:31 Z Nika533 Snowball (JOI21_ho_t2) C++17
100 / 100
426 ms 34124 KB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
using namespace std;
int n,m,T,k;
string s;
void test_case() {
	cin>>n>>m;
	int arr[n+1];
	map<int,int> mymap;
	for (int i=1; i<=n; i++) {
		cin>>arr[i];
	}
	int b[m+1];
	b[0]=0;
	int mx=0;
	int mn=0;
	set<int> myset;
	for (int i=1; i<=m; i++) {
		cin>>b[i];
		b[i]+=b[i-1];
		//cout<<i<<" "<<b[i]<<" B"<<endl;
		if (b[i]>mx) {
			mx=b[i];
			int num=b[i]-mn;
			myset.insert(num);
			if (mn==0) {
				mymap[num]=-1e18;
			}
			else {
				mymap[num]=mn;
			}
			//cout<<"B1 "<<num<<" "<<mn<<endl;
		}
		if (b[i]<mn) {
			mn=b[i];
			int num=mx-b[i];
			myset.insert(num);
			if (mx==0) {
				mymap[num]=1e18;
			}
			else {
				mymap[num]=mx;
			}
			//cout<<"B2 "<<num<<" "<<mx<<endl;
		}
	}
	vector<int> ans(n+1,0);
	for (int i=1; i<n; i++) {
		// i --- i+1
		int dist=arr[i+1]-arr[i];
		set<int> :: iterator it=myset.lower_bound(dist);
		if (it==myset.end()) {
			ans[i]+=mx;
			ans[i+1]+=-mn;
			continue;
		}
		int num=mymap[*it];
		//cout<<"AAA"<<i<<" "<<i+1<<"   "<<*it<<" "<<num<<endl;
		if (num>0) {
			if (num==1e18) {
				num=0;
			}
			ans[i]+=num;
			ans[i+1]+=dist-num;
			//cout<<i<<" "<<num<<" "<<dist-num<<endl;
		}
		else {
			if (num==-1e18) {
				num=0;
			}
			num=-num;
			ans[i+1]+=num;
			ans[i]+=dist-num;
			//cout<<i<<" "<<dist-num<<" "<<num<<endl;
		}
	}
	ans[1]+=-mn;
	ans[n]+=mx;
	for (int i=1; i<=n; i++) {
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1;
	while (T--) {
		test_case();
	}
}

Compilation message

Main.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
Main.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   91 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 584 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 584 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 123 ms 25872 KB Output is correct
21 Correct 122 ms 25656 KB Output is correct
22 Correct 127 ms 25480 KB Output is correct
23 Correct 118 ms 25392 KB Output is correct
24 Correct 129 ms 25804 KB Output is correct
25 Correct 336 ms 31984 KB Output is correct
26 Correct 310 ms 31704 KB Output is correct
27 Correct 360 ms 29760 KB Output is correct
28 Correct 302 ms 28092 KB Output is correct
29 Correct 209 ms 19036 KB Output is correct
30 Correct 75 ms 9028 KB Output is correct
31 Correct 61 ms 8300 KB Output is correct
32 Correct 55 ms 8504 KB Output is correct
33 Correct 20 ms 2956 KB Output is correct
34 Correct 105 ms 11224 KB Output is correct
35 Correct 127 ms 11968 KB Output is correct
36 Correct 426 ms 30624 KB Output is correct
37 Correct 283 ms 25292 KB Output is correct
38 Correct 326 ms 29680 KB Output is correct
39 Correct 254 ms 29876 KB Output is correct
40 Correct 188 ms 29880 KB Output is correct
41 Correct 128 ms 26612 KB Output is correct
42 Correct 54 ms 8516 KB Output is correct
43 Correct 186 ms 33720 KB Output is correct
44 Correct 123 ms 26364 KB Output is correct
45 Correct 175 ms 29928 KB Output is correct
46 Correct 206 ms 33868 KB Output is correct
47 Correct 107 ms 19392 KB Output is correct
48 Correct 183 ms 34124 KB Output is correct