結果
| 問題 |
No.28 末尾最適化
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-23 02:53:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,586 bytes |
| コンパイル時間 | 559 ms |
| コンパイル使用メモリ | 62,776 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 16:49:12 |
| 合計ジャッジ時間 | 925 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 1 |
ソースコード
#include <iostream>
#include <vector>
#include <ios>
#include <cstring>
#include <algorithm>
using namespace std;
const long long MOD = 100000009;
long long xs[10005];
int find_max(int seed, int N, int K, int B);
int main()
{
ios::sync_with_stdio(false);
int Q = 0;
cin >> Q;
vector<int> result(Q, 0);
int seed, N, K, B;
for (int i = 0; i != Q; ++i){
cin >> seed >> N >> K >> B;
result[i] = find_max(seed, N, K, B);
}
for (auto res : result) cout << res << endl;
return 0;
}
int find_max(int seed, int N, int K, int B){
xs[0] = seed;
for (int i = 0; i != N; ++i){
xs[i + 1] = 1 + (xs[i] + 12345) * xs[i] % MOD;
}
int ps[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int counts[40] = {0};
int record = 100000000;
for (auto p : ps){
int c = 0;
while (B % p == 0){
++c;
B /= p;
}
if (c){
memset(counts, 0, 40);
for (int i = 0; i != N; ++i){
int x = xs[i];
int f = 0;
for (; x % p == 0; ++f) x /= p;
counts[f] += 1;
}
int Kcopy = K;
int cum = 0;
for (int i = 0; Kcopy; ++i){
Kcopy -= counts[i];
if (Kcopy < 0){
cum += (counts[i] + Kcopy) * i;
break;
}else{
cum += counts[i] * i;
}
}
record = min(record, cum / c);
}
}
return record - 1;
}