답안 #633118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633118 2022-08-21T16:14:35 Z Iwanttobreakfree Hacker (BOI15_hac) C++17
100 / 100
488 ms 45796 KB
#include <iostream>
#include <vector>
using namespace std;
#define int long long int
int f(int a,int b){
	return min(a,b);
}
int ls(int x){
	return x<<1;
}
int rs(int x){
	return (x<<1)+1;
}
void build(int n,int l,int r,vector<int>& li,vector<int>& t){
	if(l==r)t[n]=li[l];
	else{
		int mid=(r+l)/2;
		build(ls(n),l,mid,li,t);
		build(rs(n),mid+1,r,li,t);
		t[n]=f(t[ls(n)],t[rs(n)]);
	}
}
void lazy(int n,int l,int r,int x,vector<int>& la,vector<int>& t){
	la[n]=max(la[n],x);
	t[n]=max(t[n],x);
}
void rupd(int n,int l,int r,int a,int b,int x,vector<int>& t,vector<int>& la){
	if(l>b||r<a)return;
	if(l>=a&&r<=b){
		lazy(n,l,r,x,la,t);
	}
	else{
		int mid=(r+l)/2;
		if(l!=r&&la[n]!=0){
			int y=la[n];
			lazy(ls(n),l,mid,y,la,t);
			lazy(rs(n),mid+1,r,y,la,t);
			la[n]=0;
		}
		rupd(ls(n),l,mid,a,b,x,t,la);
		rupd(rs(n),mid+1,r,a,b,x,t,la);
		t[n]=f(t[ls(n)],t[rs(n)]);
	}
}
signed main(){
    int n,ans=0,tot=0;
    cin>>n;
    vector<int> v(n),v2(2*n+1);
    for(int& i:v){
        cin>>i;
        tot+=i;
    }
    for(int i=1;i<=2*n;i++){
        v2[i]=v[(i-1)%n]+v2[i-1];
        //cout<<v2[i]-v2[i-1]<<' ';
    }
    //cout<<endl;
    vector<int> t(4*n),la(4*n);
    int dif=n/2;
    for(int i=0;i<n;i++){
        int val=v2[i+dif]-v2[i];
        if((i+dif)%n<i)rupd(1,0,n-1,(i+dif)%n,i-1,val,t,la);
        else{
            rupd(1,0,n-1,0,i-1,val,t,la);
            rupd(1,0,n-1,i+dif,n-1,val,t,la);
        }
    }
    int x=t[1];
    cout<<tot-x;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:46:11: warning: unused variable 'ans' [-Wunused-variable]
   46 |     int n,ans=0,tot=0;
      |           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 5 ms 824 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 0 ms 296 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 4 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 62 ms 7484 KB Output is correct
5 Correct 159 ms 18276 KB Output is correct
6 Correct 213 ms 22912 KB Output is correct
7 Correct 244 ms 27552 KB Output is correct
8 Correct 449 ms 45524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 5 ms 824 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 0 ms 296 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 4 ms 724 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 4 ms 724 KB Output is correct
35 Correct 62 ms 7484 KB Output is correct
36 Correct 159 ms 18276 KB Output is correct
37 Correct 213 ms 22912 KB Output is correct
38 Correct 244 ms 27552 KB Output is correct
39 Correct 449 ms 45524 KB Output is correct
40 Correct 8 ms 1220 KB Output is correct
41 Correct 15 ms 2116 KB Output is correct
42 Correct 23 ms 3040 KB Output is correct
43 Correct 164 ms 18392 KB Output is correct
44 Correct 425 ms 45440 KB Output is correct
45 Correct 78 ms 9172 KB Output is correct
46 Correct 255 ms 27540 KB Output is correct
47 Correct 438 ms 45516 KB Output is correct
48 Correct 488 ms 45796 KB Output is correct
49 Correct 399 ms 44932 KB Output is correct
50 Correct 408 ms 44912 KB Output is correct