結果

問題 No.546 オンリー・ワン
ユーザー gzlcpgzlcp
提出日時 2017-07-14 23:42:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,154 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 20:41:07
合計ジャッジ時間 1,440 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#define REP(i, n) for(long long i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
#define INF (long long)1000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int gcd(int a, int b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

int solve(int* c, int m, int n) {
	int res = 0;
	for(int i = 1; i < (1 << m); i++) {
		int num = 0;
		for(int j = i; j != 0; j >>= 1) num += j & 1;
		int lcm = 1;
		for(int j = 0; j < m; ++j) {
			if((i >> j) & 1) {
				lcm = lcm / gcd(lcm, c[j]) * c[j];
				if(lcm > n) break;
			}
		}
		if(num % 2 == 0) res -= n / lcm;
		else res += n / lcm;
	}
	return res;
}

int main() {
	int n, l, h;
	cin>>n>>l>>h;
	int c[n];
	REP(i, n) cin>>c[i];
	int res = 0;
	int a = solve(c, n, h);
	int z = 0;
	if(l > 1) z = solve(c, n, l - 1);
	REP(i, n) {
		vector<int> buf;
		REP(j, n) {
			if(j == i) continue;
			else buf.push_back(c[j]);
		}
		int b[n - 1];
		REP(j, n - 1) b[j] = buf[j];
		res += a - solve(b, n - 1, h);
		if(l > 1) res -= z - solve(b, n - 1, l - 1);
	}
	cout<<res<<endl;
}
0