結果
| 問題 |
No.12 限定された素数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-19 21:52:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,515 bytes |
| コンパイル時間 | 824 ms |
| コンパイル使用メモリ | 71,420 KB |
| 最終ジャッジ日時 | 2025-01-06 16:54:08 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘void stage(std::array<int, 10>&, int, int)’:
main.cpp:27:9: error: no match for ‘operator[]’ (operand types are ‘std::array<int, 10>’ and ‘int’)
27 | digs[n % 10] += direction;
| ^
main.cpp: In function ‘int main(int, char**)’:
main.cpp:35:23: error: variable ‘std::array<int, 10> as’ has initializer but incomplete type
35 | std::array<int, 10> as{};
| ^~
main.cpp:45:23: error: variable ‘std::array<int, 10> nums’ has initializer but incomplete type
45 | std::array<int, 10> nums{};
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<bitset>
static int const MAX = 5000000 + 1;
std::vector<int> primes() {
std::vector<int> rs;
std::bitset<MAX> ps;
ps.set();
ps[0] = ps[1] = 0;
for(int i{2}; i < MAX; ++i) {
if(!ps[i]) continue;
rs.push_back(i);
for(int j{i * 2}; j < MAX; j += i) {
ps[j] = 0;
}
}
return rs;
}
void stage(std::array<int, 10>& digs, int n, int direction) {
while(n > 0) {
digs[n % 10] += direction;
n /= 10;
}
}
int main(int, char**) {
int N;
std::cin >> N;
std::array<int, 10> as{};
for(int i{}; i < N; ++i) {
int t;
std::cin >> t;
as[t] = 1;
}
std::vector<int> ps = primes();
int ans{-1};
int last{};
std::array<int, 10> nums{};
for(int i{}; i < ps.size(); ++i) {
stage(nums, ps[i], 1);
for(int j{}; j < 10; ++j) {
if(as[j]) continue;
while(nums[j] > 0) {
stage(nums, ps[last++], -1);
}
}
// std::cout << "### i=" << i << ", ps[i]=" << ps[i] << ", last=" << last << std::endl;
bool flg{true};
for(int j{}; j < 10; ++j) {
if(!as[j]) continue;
if(nums[j] == 0) {
flg = false;
}
}
if(i >= last && flg) {
// std::cout << "enter i=" << i << std::endl;
int k, l;
k = last == 0 ?
1 :
ps[last - 1] + 1;
l = i == (ps.size() - 1) ?
MAX - 1 :
ps[i + 1] - 1;
ans = std::max(ans, l - k);
}
}
std::cout << ans << std::endl;
}