답안 #604431

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604431 2022-07-25T06:25:44 Z chirathnirodha Snowball (JOI21_ho_t2) C++17
100 / 100
117 ms 15468 KB
//Coded by Chirath Nirodha
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define P push
#define I insert
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll mod=1e9+7;
inline void io(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
void solve(){
    io();

	ll n,m;cin>>n>>m;
	ll x[n];
	for(int i=0;i<n;i++){
		cin>>x[i];
		x[i]+=10000000000000;
	}
	ll cur=0;
	ll prmax[m],prmin[m];
	memset(prmax,0,sizeof(prmax));memset(prmin,0,sizeof(prmin));
	vector<ll> v;
	for(int i=0;i<m;i++){
		ll tt;cin>>tt;cur+=tt;
		prmax[i]=max(prmax[i],cur);
		if(i>0)prmax[i]=max(prmax[i],prmax[i-1]);
		prmin[i]=min(prmin[i],cur);
		if(i>0)prmin[i]=min(prmin[i],prmin[i-1]);
		v.PB(prmax[i]-prmin[i]);
	}
	ll w[n];memset(w,0,sizeof(w));
	w[0]+=-prmin[m-1];
	w[n-1]+=prmax[m-1];
	for(int i=0;i<n-1;i++){
		ll dif=x[i+1]-x[i];
		auto lo=lower_bound(v.begin(),v.end(),dif);
		int ind;
		if(lo==v.end() || *lo==dif){
			if(lo==v.end())lo--;
			ind=lo-v.begin();
			w[i]+=prmax[ind];
			w[i+1]+=-prmin[ind];
			continue;
		}
		ind=lo-v.begin();
		if(ind==0){
			w[i]+=min(dif,prmax[ind]);
			w[i+1]+=min(dif,-prmin[ind]);
		}
		else{
			if(prmin[ind]==prmin[ind-1]){
				w[i+1]+=-prmin[ind];
				w[i]+=dif+prmin[ind];
			}
			else{
				w[i]+=prmax[ind];
				w[i+1]+=dif-prmax[ind];
			}
		}
	}
	for(int i=0;i<n;i++)cout<<w[i]<<" ";cout<<endl;
}
int main(){
    io();
	solve();
	//int t;cin>>t;for(int i=0;i<t;i++)solve();
    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:73:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   73 |  for(int i=0;i<n;i++)cout<<w[i]<<" ";cout<<endl;
      |  ^~~
Main.cpp:73:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   73 |  for(int i=0;i<n;i++)cout<<w[i]<<" ";cout<<endl;
      |                                      ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 27 ms 7272 KB Output is correct
21 Correct 28 ms 7064 KB Output is correct
22 Correct 26 ms 6940 KB Output is correct
23 Correct 32 ms 6800 KB Output is correct
24 Correct 30 ms 7228 KB Output is correct
25 Correct 97 ms 13488 KB Output is correct
26 Correct 90 ms 13500 KB Output is correct
27 Correct 90 ms 13068 KB Output is correct
28 Correct 109 ms 13224 KB Output is correct
29 Correct 89 ms 12840 KB Output is correct
30 Correct 78 ms 12200 KB Output is correct
31 Correct 62 ms 11580 KB Output is correct
32 Correct 78 ms 11780 KB Output is correct
33 Correct 9 ms 1744 KB Output is correct
34 Correct 91 ms 13872 KB Output is correct
35 Correct 105 ms 13244 KB Output is correct
36 Correct 110 ms 13528 KB Output is correct
37 Correct 92 ms 13340 KB Output is correct
38 Correct 98 ms 13312 KB Output is correct
39 Correct 117 ms 13380 KB Output is correct
40 Correct 72 ms 13264 KB Output is correct
41 Correct 37 ms 7876 KB Output is correct
42 Correct 65 ms 11700 KB Output is correct
43 Correct 78 ms 15032 KB Output is correct
44 Correct 31 ms 7744 KB Output is correct
45 Correct 63 ms 13224 KB Output is correct
46 Correct 87 ms 15172 KB Output is correct
47 Correct 86 ms 15404 KB Output is correct
48 Correct 82 ms 15468 KB Output is correct