답안 #862927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862927 2023-10-19T11:33:53 Z eitanelb Candies (JOI18_candies) C++14
100 / 100
372 ms 23828 KB
#include<bits/stdc++.h> 
#define ll long long 
using namespace std; 
#define all(x) (x).begin(),(x).end() 
#define vll vector<long long> 
#define pvll pair<vll,vll> 
#define x first 
#define y second 
//first index=left 
//1=excluding 
//{{{},{}},{{},{}}}; 
void gtmx(ll&a,ll b){if(b>a)a=b;} 
vll get1(vll f,vll s){ 
    if(!s.size())return f;if(!f.size())return s; 
    int n=f.size()+s.size(); 
    vll toz(n); 
    for(int i=0;f.size()>i;++i)gtmx(toz[i],f[i]); 
    for(int i=0;s.size()>i;++i)gtmx(toz[i],s[i]); 
    int nf=1; 
    for(int i=2;n>=i;++i){ 
        if(i-nf>s.size())++nf; 
        while(nf>1&&i-nf<s.size()&&f[nf-1]+s[i-nf-1]<f[nf-2]+s[i-nf])--nf; 
        while(nf<i-1&&nf<f.size()&&f[nf-1]+s[i-nf-1]<f[nf]+s[i-nf-2])++nf; 
        gtmx(toz[i-1],f[nf-1]+s[i-nf-1]); 
        if(i==4&&toz[i-1]>4000000000){ 
            cout<<"hi\n"; 
        } 
    } 
    return toz; 
} 
vll uni(vll f,vll s){ 
    if(s.size()>f.size())swap(s,f); 
    for(int i=0;s.size()>i;++i)gtmx(f[i],s[i]); 
    return f; 
} 
pair<pvll,pvll> rec (vector<int>&nuts,int st,int en){ 
    if(en-st<=2){ 
        if(en==st)return{{{(ll)nuts[st]},{}},{{},{}}}; 
        if(en==st+1)return {{{max(nuts[st],nuts[en])},{nuts[st]}},{{nuts[en]},{}}}; 
        return {{{max({nuts[st],nuts[st+1],nuts[en]}),nuts[st]+nuts[en]},{max(nuts[st],nuts[st+1])}},{{max(nuts[st+1],nuts[en])},{nuts[st+1]}}}; 
    } 
    int g=(en+st)/2; 
    auto x1=rec(nuts,st,g); 
    auto x2=rec(nuts,g+1,en); 
    return{{uni(get1(x1.x.y,x2.x.x),get1(x1.x.x,x2.y.x)), 
        uni(get1(x1.x.y,x2.x.y),get1(x1.x.x,x2.y.y)) 
    },{uni(get1(x1.y.y,x2.x.x),get1(x1.y.x,x2.y.x)), 
        uni(get1(x1.y.y,x2.x.y),get1(x1.y.x,x2.y.y)) 
    }}; 
} 
vector<long long> Nuts(int N, vector<int> nuts){ 
    return rec(nuts,0,N-1).x.x; 
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin>>n;
    vector<int> nuts(n);
    for(int i=0;i<n;i++) cin>>nuts[i];
    
    vector<long long> ans = Nuts(n, nuts);
    
    for(long long c : ans) cout<<c<<endl;
    return 0;
}

Compilation message

candies.cpp: In function 'std::vector<long long int> get1(std::vector<long long int>, std::vector<long long int>)':
candies.cpp:14:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   14 |     if(!s.size())return f;if(!f.size())return s;
      |     ^~
candies.cpp:14:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   14 |     if(!s.size())return f;if(!f.size())return s;
      |                           ^~
candies.cpp:17:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |     for(int i=0;f.size()>i;++i)gtmx(toz[i],f[i]);
      |                 ~~~~~~~~^~
candies.cpp:18:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |     for(int i=0;s.size()>i;++i)gtmx(toz[i],s[i]);
      |                 ~~~~~~~~^~
candies.cpp:21:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         if(i-nf>s.size())++nf;
      |            ~~~~^~~~~~~~~
candies.cpp:22:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         while(nf>1&&i-nf<s.size()&&f[nf-1]+s[i-nf-1]<f[nf-2]+s[i-nf])--nf;
      |                     ~~~~^~~~~~~~~
candies.cpp:23:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         while(nf<i-1&&nf<f.size()&&f[nf-1]+s[i-nf-1]<f[nf]+s[i-nf-2])++nf;
      |                       ~~^~~~~~~~~
candies.cpp: In function 'std::vector<long long int> uni(std::vector<long long int>, std::vector<long long int>)':
candies.cpp:33:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |     for(int i=0;s.size()>i;++i)gtmx(f[i],s[i]);
      |                 ~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 540 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 4 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 508 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 3 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 540 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 4 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 508 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 3 ms 676 KB Output is correct
21 Correct 329 ms 23340 KB Output is correct
22 Correct 332 ms 23284 KB Output is correct
23 Correct 333 ms 23288 KB Output is correct
24 Correct 294 ms 23028 KB Output is correct
25 Correct 298 ms 23032 KB Output is correct
26 Correct 296 ms 23020 KB Output is correct
27 Correct 308 ms 23412 KB Output is correct
28 Correct 297 ms 23292 KB Output is correct
29 Correct 298 ms 23344 KB Output is correct
30 Correct 301 ms 23324 KB Output is correct
31 Correct 302 ms 23272 KB Output is correct
32 Correct 341 ms 23384 KB Output is correct
33 Correct 317 ms 23120 KB Output is correct
34 Correct 319 ms 23064 KB Output is correct
35 Correct 318 ms 23320 KB Output is correct
36 Correct 332 ms 23540 KB Output is correct
37 Correct 365 ms 23588 KB Output is correct
38 Correct 372 ms 23540 KB Output is correct
39 Correct 300 ms 23392 KB Output is correct
40 Correct 307 ms 23380 KB Output is correct
41 Correct 303 ms 23220 KB Output is correct
42 Correct 295 ms 23536 KB Output is correct
43 Correct 344 ms 23500 KB Output is correct
44 Correct 303 ms 23540 KB Output is correct
45 Correct 318 ms 23828 KB Output is correct
46 Correct 298 ms 23416 KB Output is correct
47 Correct 308 ms 23556 KB Output is correct
48 Correct 331 ms 23292 KB Output is correct
49 Correct 317 ms 23360 KB Output is correct
50 Correct 326 ms 23276 KB Output is correct