結果
問題 | No.546 オンリー・ワン |
ユーザー | 👑 はまやんはまやん |
提出日時 | 2017-07-14 23:05:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 2,420 bytes |
コンパイル時間 | 3,340 ms |
コンパイル使用メモリ | 167,332 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-07-29 14:38:18 |
合計ジャッジ時間 | 2,039 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 4 ms
4,376 KB |
testcase_10 | AC | 7 ms
4,380 KB |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define fore(i,a) for(auto &i:a) #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------------------------------------------------------- typedef long long ll; #define CMAX 1010 int noinit = 1; ll memo[CMAX][CMAX]; ll aCb(ll a, ll b) { if (noinit) { rep(i, 0, CMAX) rep(j, 0, CMAX) memo[i][j] = -1; noinit = 0; } if (b == 0 || a == b) return 1; if (0 <= memo[a][b]) return memo[a][b]; return memo[a][b] = aCb(a - 1, b - 1) + aCb(a - 1, b); } ll countMod(ll _min, ll _max, ll mod) { if (_max % mod == 0) { if (_min % mod == 0) return _max / mod - _min / mod + 1; else return _max / mod - _min / mod; } else { if (_min % mod == 0) return _max / mod - _min / mod + 1; else return _max / mod - _min / mod; } } ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N; ll L, H; ll C[11]; ll cn[11]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> L >> H; rep(i, 0, N) cin >> C[i]; ll ans = 0; rep(i, 0, N) { vector<ll> CC; ll d = 0; rep(j, 0, N) if (i != j) CC.push_back(C[j]); rep(mask, 0, 1<<(N - 1)) { ll lc = C[i]; int cnt = 0; rep(j, 0, N - 1) if (mask & (1 << j)) lc = lcm(lc, CC[j]), cnt++; ll c = countMod(L, H, lc); //cout << c << endl; if (cnt % 2 == 0) d += c; else d -= c; } ans += d; //cout << d << endl; } cout << ans << endl; }