結果
| 問題 | No.12 限定された素数 | 
| コンテスト | |
| ユーザー |  hogeover30 | 
| 提出日時 | 2015-02-17 15:44:22 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                CE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,135 bytes | 
| コンパイル時間 | 342 ms | 
| コンパイル使用メモリ | 52,948 KB | 
| 最終ジャッジ日時 | 2024-11-14 19:00:10 | 
| 合計ジャッジ時間 | 673 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
            
            
            
            
            ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:5: error: ‘vector’ was not declared in this scope
    8 |     vector<int> primes;
      |     ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:8:12: error: expected primary-expression before ‘int’
    8 |     vector<int> primes;
      |            ^~~
main.cpp:9:12: error: expected primary-expression before ‘int’
    9 |     vector<int> v;
      |            ^~~
main.cpp:11:9: error: ‘primes’ was not declared in this scope
   11 |         primes.push_back(i);
      |         ^~~~~~
main.cpp:14:9: error: ‘v’ was not declared in this scope
   14 |         v.push_back(x);
      |         ^
main.cpp:22:25: error: ‘v’ was not declared in this scope
   22 |         int s=0, e=0, x=v[s];
      |                         ^
main.cpp:27:27: error: ‘primes’ was not declared in this scope
   27 |                     int L=primes[e]-1;
      |                           ^~~~~~
main.cpp:40:25: error: ‘primes’ was not declared in this scope
   40 |                 int L=e<primes.size()?primes[e]-1:5000000;
      |                         ^~~~~~
            
            ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
const int N=5000001;
int c[N];
int main()
{
    vector<int> primes;
    vector<int> v;
    for(int i=2;i<N;++i) if (!c[i]) {
        primes.push_back(i);
        int x=0;
        for(int t=i;t>0;t/=10) x|=1<<(t%10);
        v.push_back(x);
        for(int j=i+i;j<N;j+=i) c[j]=1;
    }
    int n;
    while (cin>>n) {
        int a=0;
        for(int i=0;i<n;++i) { int t; cin>>t; a|=1<<t; }
        int s=0, e=0, x=v[s];
        int res=-1;
        while (s<v.size() and e<v.size()) {
            if ((x|v[e]|a)>a) {
                if (x==a and s<e) {
                    int L=primes[e]-1;
                    int K=!!s*primes[s-1]+1;
                    res=max(res, L-K);
                }
                s=e+1;
                e=s;
                x=v[e];
            }
            else {
                x|=v[e];
                ++e;
            }
            if (x==a) {
                int L=e<primes.size()?primes[e]-1:5000000;
                int K=!!s*primes[s-1]+1;
                res=max(res, L-K);
            }
        }
        cout<<res<<endl;
    }
}
            
            
            
        