제출 #1138859

#제출 시각아이디문제언어결과실행 시간메모리
1138859SmuggingSpunSkyscraper (JOI16_skyscraper)C++20
15 / 100
171 ms91116 KiB
#include<bits/stdc++.h> #define taskname "C" using namespace std; typedef long long ll; const int mod = 1e9 + 7; void add(int& a, int b){ if((a += b) >= mod){ a -= mod; } } int n, L; namespace sub1{ void solve(){ vector<int>a(n), p(n); for(int& x : a){ cin >> x; } int ans = 0; iota(p.begin(), p.end(), 0); do{ int sum = 0; for(int i = 1; i < n; i++){ sum += abs(a[p[i]] - a[p[i - 1]]); } if(sum <= L){ ans++; if(sum == 6){ for(int i = 0; i < n; i++){ cout << a[p[i]] << " "; } cout << endl; } } } while(next_permutation(p.begin(), p.end())); cout << ans; } } namespace sub2{ int dp[1 << 14][14][101]; void solve(){ vector<int>a(n); for(int& x : a){ cin >> x; } memset(dp, 0, sizeof(dp)); for(int mask = 1; mask < (1 << n); mask++){ vector<int>bit; for(int i = 0; i < n; i++){ if(1 << i & mask){ bit.emplace_back(i); } } if(bit.size() == 1){ dp[mask][bit[0]][0] = 1; } else{ for(int& i : bit){ for(int& j : bit){ if(i != j){ for(int d = abs(a[i] - a[j]), k = d; k <= L; k++){ add(dp[mask][i][k], dp[mask ^ (1 << i)][j][k - d]); } } } } } } int ans = 0; for(int i = 0; i < n; i++){ for(int j = 0; j <= L; j++){ add(ans, dp[(1 << n) - 1][i][j]); } } cout << ans; } } namespace sub3{ const int lim = 1e2 + 5; const int LIM = 1e3 + 5; int a[lim], dp[2][lim][LIM][3]; void solve(){ memset(dp, 0, sizeof(dp)); bool cur = true, pre = false; for(int i = dp[cur][0][0][0] = 1; i <= n; i++){ cin >> a[i]; } sort(a + 1, a + n + 1); if(n == 1){ return void(cout << 1); } if(n == 2){ return void(cout << (int(a[2] - a[1] <= L) << 1)); } for(int i = 1; i < n; i++){ swap(cur, pre); int delta = a[i + 1] - a[i]; for(int j = 0; j <= i; j++){ for(int k = 0; k <= L; k++){ for(int t = 0; t < 3; t++){ int after_sum = max(-1LL, ll(k) - 1LL * delta * ((j << 1) - t)); if(j >= t && after_sum > -1 && after_sum <= L){ dp[cur][j][k][t] = 1LL * j * dp[pre][j + 1][after_sum][t] % mod; if(i + j - t < n){ add(dp[cur][j][k][t], 1LL * (j - t) * dp[pre][j - 1][after_sum][t] % mod); add(dp[cur][j][k][t], 1LL * ((j << 1) - t) * dp[pre][j][after_sum][t] % mod); } if(t > 0 && i + j - t <= n){ add(dp[cur][j][k][t], 1LL * (3 - t) * dp[pre][j - 1][after_sum][t - 1] % mod); add(dp[cur][j][k][t], 1LL * (3 - t) * dp[pre][j][after_sum][t - 1] % mod); } } else{ dp[cur][j][k][t] = 0; } } } } } int ans = 0; for(int j = 1; j < 3; j++){ for(int k = 0; k <= L; k++){ add(ans, dp[cur][j][k][j]); } } cout << ans; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n >> L; if(n <= 8){ sub1::solve(); } else if(n <= 14 && L <= 100){ sub2::solve(); } else{ sub3::solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:131:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...