답안 #337971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337971 2020-12-22T08:20:25 Z beksultan04 스카이라인 (IZhO11_skyline) C++14
0 / 100
2000 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[201][140001],q[N],n;
int rec(int sum,int cnt){
    int i,f=0;
    for (i=1;i<=n;++i){
        if (q[i] > 0)f=1;
    }
    if (!f){
        ret sum;

    }
    int ans = INF;


    for (i=1;i<=n;++i){
        if (q[i] <= 0)continue;
        int mn = q[i];
        q[i]-=mn;
        ans = min(ans,rec(sum+mn*3,1));
        q[i]+=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,1));
                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,1));
                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,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,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,1));
                q[i-2]+=mn;
                q[i-1]+=mn;
                q[i]+=mn;
            }
        }
    }

    ret dp[cnt][sum]= ans;
}
main(){
    int i,ans=INF;
    scan1(n)
    for (i=1;i<=n;++i){
        scan1(q[i])
    }
    for (i=1;i<=n;++i){
        int mn = q[i];
        q[i]-=mn;
        ans = min(ans,rec(mn*3,1));
        q[i]+=mn;
        if (i > 1){
            if (q[i-1] <= q[i]){
                mn = q[i-1];
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(mn*5,1));
                q[i-1]+=mn;
                q[i]+=mn;
            }
            else {
                mn = q[i];
                q[i-1]-=mn;
                q[i]-=mn;
                ans = min(ans,rec(mn*5,1));
                q[i-1]+=mn;
                q[i]+=mn;
            }
        }
        if (i > 2){
            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,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,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,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])
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Execution timed out 2071 ms 364 KB Time limit exceeded
5 Halted 0 ms 0 KB -