結果

問題 No.6 使いものにならないハッシュ
ユーザー A63635985A63635985
提出日時 2018-03-01 01:27:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,233 ms / 5,000 ms
コード長 2,063 bytes
コンパイル時間 727 ms
コンパイル使用メモリ 81,496 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:11:16
合計ジャッジ時間 12,470 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1,233 ms
4,352 KB
testcase_03 AC 35 ms
4,352 KB
testcase_04 AC 56 ms
4,348 KB
testcase_05 AC 132 ms
4,352 KB
testcase_06 AC 326 ms
4,348 KB
testcase_07 AC 92 ms
4,348 KB
testcase_08 AC 236 ms
4,348 KB
testcase_09 AC 28 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 48 ms
4,352 KB
testcase_12 AC 573 ms
4,352 KB
testcase_13 AC 13 ms
4,348 KB
testcase_14 AC 29 ms
4,348 KB
testcase_15 AC 356 ms
4,352 KB
testcase_16 AC 112 ms
4,352 KB
testcase_17 AC 537 ms
4,348 KB
testcase_18 AC 1,072 ms
4,352 KB
testcase_19 AC 497 ms
4,348 KB
testcase_20 AC 472 ms
4,348 KB
testcase_21 AC 18 ms
4,348 KB
testcase_22 AC 484 ms
4,352 KB
testcase_23 AC 514 ms
4,348 KB
testcase_24 AC 454 ms
4,352 KB
testcase_25 AC 136 ms
4,352 KB
testcase_26 AC 670 ms
4,348 KB
testcase_27 AC 336 ms
4,352 KB
testcase_28 AC 196 ms
4,348 KB
testcase_29 AC 789 ms
4,348 KB
testcase_30 AC 690 ms
4,348 KB
testcase_31 AC 489 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:28: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         cout << sss[current]<<endl;
                            ^

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
#include <map>
using namespace std;
int hh(int x){
        if(x<10)return x;
        ostringstream to_str;
        to_str << x;
        string str=to_str.str();
        int sum=0;
        for(int i=0 ; i<str.size() ; i++ ){
                string tmp="";tmp+=str[i];
                istringstream to_int(tmp);
                int x;
                to_int>>x;
                sum+=x;
        }
        return hh(sum);
}
struct Info{
        bool sign;
        int locate;
};
int main(){
        int N,K;
        cin >> N >> K;
        vector <int> prime;
        vector <int> sss;
        for(int i=N ; i<=K ; i++ ){
                bool sign=true;
                for(int l=2 ; l<=sqrt(i) ; l++ ){
                        if(i%l==0){
                                sign=false;
                                break;
                        }
                }
                if(!sign || i==1 )continue;
                prime.push_back(hh(i));
                sss.push_back(i);
        }
        vector<int>::iterator itr;
        map<int,Info> used;
        int current,counter=0,max=0;
        int start;bool sign=true;
        for(int i=0 ; i<prime.size() ; i++ ){
                if(used[prime[i]].sign){
                        if(max<=counter){
                                max=counter;
                                current=start;
                        }
                        used[prime[i]].sign=false;
                        for(int j=0 ; j<i ; j++ )
                                used[prime[j]].sign=false;
                        i=used[prime[i]].locate+1;
                        sign=true;
                        counter=0;
                }if(sign){
                        start=i;
                        sign=false;
                }
                used[prime[i]].sign=true;
                used[prime[i]].locate=i;
                counter++;
        }if(max<=counter)
                current=start;
        cout << sss[current]<<endl;
}
0