Submission #337983

# Submission time Handle Problem Language Result Execution time Memory
337983 2020-12-22T08:43:09 Z beksultan04 Skyline (IZhO11_skyline) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 1e6+12,INF=1e9+7;
int dp[301][301][301],q[N],n;
int rec(int sum,int j,int b,int c){
    int i,f=0;
    if (dp[i][b][c])ret dp[i][b][c];
    for (i=j;i<=n;++i){
        if (q[i] > 0 && q[i-1] > 0)f=1;
    }
    if (!f){
        int x = 0;
        for (i=1;i<=n;++i)x+=q[i];
        sum+=x*3;
        ret sum;
    }
    int ans = INF;


    for (i=j;i<=n;++i){
        if (q[i] <= 0)continue;
        int mn;
        if (i > 1&& q[i-1] > 0){
            if (q[i-1] <= q[i]){
                mn = q[i-1];
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(sum+mn*5,i,b+1,c));
                q[i-1]+=mn;
                q[i]+=mn;
            }
            else {
                mn = q[i];
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(sum+mn*5,i,b+1,c));
                q[i-1]+=mn;
                q[i]+=mn;
            }
        }
        if (i > 2 && q[i-2] > 0  && q[i-1] > 0){
            if (q[i-1] <= q[i] && q[i-1] <= q[i-2]){
                mn = q[i-1];
                q[i-2]-=mn;
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(sum+mn*7,i,b,c+1));
                q[i-2]+=mn;
                q[i-1]+=mn;
                q[i]+=mn;
            }

            if (q[i-2] >= q[i] && q[i] <= q[i-1]){
                mn = q[i];
                q[i-2]-=mn;
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(sum+mn*7,i,b,c+1));
                q[i-2]+=mn;
                q[i-1]+=mn;
                q[i]+=mn;
            }
            if (q[i-1] <= q[i] && q[i-1] <= q[i-2]){
                mn = q[i-1];
                q[i-2]-=mn;
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(sum+mn*7,i,b,c+1));
                q[i-2]+=mn;
                q[i-1]+=mn;
                q[i]+=mn;
            }
        }
    }

    ret dp[i][b][c] = ans;
}
main(){
    int i,ans=INF,b=0,c=0;
    scan1(n)
    for (i=1;i<=n;++i){
        scan1(q[i])
    }

    for (i=1;i<=n;++i){
        if (q[i] <= 0)continue;
        int mn;
        if (i > 1&& q[i-1] > 0){
            if (q[i-1] <= q[i]){
                mn = q[i-1];
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(mn*5,i,b+1,c));
                q[i-1]+=mn;
                q[i]+=mn;
            }
            else {
                mn = q[i];
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(mn*5,i,b+1,c));
                q[i-1]+=mn;
                q[i]+=mn;
            }
        }
        if (i > 2 && q[i-2] > 0  && q[i-1] > 0){
            if (q[i-1] <= q[i] && q[i-1] <= q[i-2]){
                mn = q[i-1];
                q[i-2]-=mn;
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(mn*7,i,b,c+1));
                q[i-2]+=mn;
                q[i-1]+=mn;
                q[i]+=mn;
            }

            if (q[i-2] >= q[i] && q[i] <= q[i-1]){
                mn = q[i];
                q[i-2]-=mn;
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(mn*7,i,b,c+1));
                q[i-2]+=mn;
                q[i-1]+=mn;
                q[i]+=mn;
            }
            if (q[i-1] <= q[i] && q[i-1] <= q[i-2]){
                mn = q[i-1];
                q[i-2]-=mn;
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(mn*7,i,b,c+1));
                q[i-2]+=mn;
                q[i-1]+=mn;
                q[i]+=mn;
            }
        }
    }
    cout <<ans;

}







Compilation message

skyline.cpp:94:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   94 | main(){
      |      ^
skyline.cpp: In function 'int main()':
skyline.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
skyline.cpp:96:5: note: in expansion of macro 'scan1'
   96 |     scan1(n)
      |     ^~~~~
skyline.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
skyline.cpp:98:9: note: in expansion of macro 'scan1'
   98 |         scan1(q[i])
      |         ^~~~~
skyline.cpp: In function 'long long int rec(long long int, long long int, long long int, long long int)':
skyline.cpp:23:19: warning: 'i' is used uninitialized in this function [-Wuninitialized]
   23 |     if (dp[i][b][c])ret dp[i][b][c];
      |         ~~~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -