# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421709 |
2021-06-09T11:10:35 Z |
Kerim |
Snowball (JOI21_ho_t2) |
C++17 |
|
48 ms |
3912 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;}
ll arr[MAXN],w[MAXN];
pair<ll,ll>rng[3];
const ll B=1e16;
void print(pair<ll,ll>a){
cout<<a.ff<<" "<<a.ss<<endl;
}
int main(){
//freopen("file.in", "r", stdin);
int n,q;
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)
scanf("%lld",arr+i);
arr[0]=-B;
arr[n+1]=B;
for(int i=1;i<=q;i++)
scanf("%lld",w+i);
for(int i=1;i<=n;i++){
ll x=arr[i-1],y=arr[i],z=arr[i+1],A,B;
rng[0]=mp(x,x);
rng[1]=mp(y,y);
rng[2]=mp(z,z);
bool a=0,b=0;
for(int j=1;j<=q;j++){
if(!w[j])continue;
x+=w[j];
y+=w[j];
z+=w[j];
umin(rng[0].ff,x);umax(rng[0].ss,x);
umin(rng[1].ff,y);umax(rng[1].ss,y);
umin(rng[2].ff,z);umax(rng[2].ss,z);
if(rng[0].ss>=rng[1].ff and !a){
a=1;
if(w[j]<0)A=rng[0].ss;
else A=rng[1].ff;
}
if(rng[1].ss>=rng[2].ff and !b){
b=1;
if(w[j]<0)B=rng[1].ss;
else B=rng[2].ff;
}
}
if(!a)A=rng[1].ff;
if(!b)B=rng[1].ss;
printf("%lld\n",B-A);
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d%d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%lld",arr+i);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%lld",w+i);
| ~~~~~^~~~~~~~~~~~
Main.cpp:63:9: warning: 'B' may be used uninitialized in this function [-Wmaybe-uninitialized]
63 | printf("%lld\n",B-A);
| ~~~~~~^~~~~~~~~~~~~~
Main.cpp:63:9: warning: 'A' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
37 ms |
380 KB |
Output is correct |
5 |
Correct |
37 ms |
380 KB |
Output is correct |
6 |
Correct |
48 ms |
356 KB |
Output is correct |
7 |
Correct |
44 ms |
372 KB |
Output is correct |
8 |
Correct |
39 ms |
372 KB |
Output is correct |
9 |
Correct |
39 ms |
352 KB |
Output is correct |
10 |
Correct |
37 ms |
332 KB |
Output is correct |
11 |
Correct |
19 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
39 ms |
392 KB |
Output is correct |
16 |
Correct |
37 ms |
376 KB |
Output is correct |
17 |
Correct |
38 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
5 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
37 ms |
380 KB |
Output is correct |
5 |
Correct |
37 ms |
380 KB |
Output is correct |
6 |
Correct |
48 ms |
356 KB |
Output is correct |
7 |
Correct |
44 ms |
372 KB |
Output is correct |
8 |
Correct |
39 ms |
372 KB |
Output is correct |
9 |
Correct |
39 ms |
352 KB |
Output is correct |
10 |
Correct |
37 ms |
332 KB |
Output is correct |
11 |
Correct |
19 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
39 ms |
392 KB |
Output is correct |
16 |
Correct |
37 ms |
376 KB |
Output is correct |
17 |
Correct |
38 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
5 ms |
436 KB |
Output is correct |
20 |
Incorrect |
38 ms |
3912 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |