Submission #95946

#TimeUsernameProblemLanguageResultExecution timeMemory
95946Retro3014Skyscraper (JOI16_skyscraper)C++17
5 / 100
4 ms376 KiB
#include <iostream> #include <stdio.h> #include <vector> #include <algorithm> #include <deque> using namespace std; typedef long long ll; #define MAX_N 100 #define DIV 1000000007LL int N; vector<int> v; ll ans; bool chk[MAX_N+1]; int arr[MAX_N+1]; ll L, L2; int zero(int x){ return (x>0?x:-x); } int cost(int x, int y){ if(x==-1 || y==-1) return 0; return zero(v[x]-v[y]); } void dfs(int x){ if(x==N){ if(L>=L2){ ans++; return; } }else{ for(int i=0; i<N; i++){ if(!chk[i]){ arr[x] = i; chk[i] = true; if(x!=0){ L2+=(ll)zero(v[arr[x]]-v[arr[x-1]]); } dfs(x+1); chk[i] = false; if(x!=0){ L2-=(ll)zero(v[arr[x]]-v[arr[x-1]]); } arr[x] = 0; } } }} void solve1(){ dfs(0); return;} #define MAX_K 20000 #define MAX_N2 14 #define MAX_L 100 ll dp[MAX_K+1][MAX_N2+1][MAX_L+1]; bool in[MAX_K+1][MAX_N2+1][MAX_L+1]; struct S{ S (int x, int y, int z) : x(x), y(y), z(z) {} int x, y, z; }; deque<S> dq; void solve2(){ dp[0][0][0] = 1; in[0][0][0] = true; dq.push_back({0, -1, 0}); while(!dq.empty()){ S now = dq.front(); dq.pop_front(); int two = 1; for(int i=0; i<N; i++){ if((two&now.x==0)){ if(now.z+cost(i, now.y)<=L){ S add(now.x+two, i, now.z+cost(i, now.y)); dp[add.x][add.y][add.z]+=dp[now.x][now.y][now.z]; dp[add.x][add.y][add.z]=dp[add.x][add.y][add.z]%DIV; if(!in[add.x][add.y][add.z]){ dq.push_back(add); in[add.x][add.y][add.z] = true; } } } two*=2; } } int idx = (1<<N)-1; for(int i=0; i<N; i++){ for(int j=0; j<=L; j++){ ans+=dp[idx][i][j]; ans=ans%DIV; } } return; } int main(){ scanf("%d%lld", &N, &L); for(int i=0; i<N; i++){ int x; scanf("%d", &x); v.push_back(x); } if(N<=8){ solve1(); }else{ solve2(); } printf("%lld", ans); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve2()':
skyscraper.cpp:77:17: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
    if((two&now.x==0)){
            ~~~~~^~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld", &N, &L);
  ~~~~~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:103:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d", &x); v.push_back(x);
          ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...