結果
問題 | No.3015 アンチローリングハッシュ |
ユーザー | yuppe19 😺 |
提出日時 | 2015-11-02 09:39:54 |
言語 | C++11 (gcc 11.4.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,489 bytes |
コンパイル時間 | 590 ms |
コンパイル使用メモリ | 53,040 KB |
最終ジャッジ日時 | 2024-11-14 19:23:56 |
合計ジャッジ時間 | 1,301 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:27:6: error: variable or field ‘init_by_array’ declared void 27 | void init_by_array(vector<unsigned int> init_key) { | ^~~~~~~~~~~~~ main.cpp:27:20: error: ‘vector’ was not declared in this scope 27 | void init_by_array(vector<unsigned int> init_key) { | ^~~~~~ main.cpp:4:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’? 3 | #include <sys/time.h> +++ |+#include <vector> 4 | using namespace std; main.cpp:27:27: error: expected primary-expression before ‘unsigned’ 27 | void init_by_array(vector<unsigned int> init_key) { | ^~~~~~~~ main.cpp:84:6: error: variable or field ‘shuffle’ declared void 84 | void shuffle(vector<T> &v) { | ^~~~~~~ main.cpp:84:14: error: ‘vector’ was not declared in this scope 84 | void shuffle(vector<T> &v) { | ^~~~~~ main.cpp:84:14: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’? main.cpp:84:22: error: expected primary-expression before ‘>’ token 84 | void shuffle(vector<T> &v) { | ^ main.cpp:84:25: error: ‘v’ was not declared in this scope 84 | void shuffle(vector<T> &v) { | ^ main.cpp: In function ‘int main()’: main.cpp:113:3: error: ‘vector’ was not declared in this scope 113 | vector<unsigned int> init; | ^~~~~~ main.cpp:113:3: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’? main.cpp:113:10: error: expected primary-expression before ‘unsigned’ 113 | vector<unsigned int> init; | ^~~~~~~~ main.cpp:114:3: error: ‘init’ was not declared in this scope; did you mean ‘int’? 114 | init.push_back(0x123); | ^~~~ | int main.cpp:120:3: error: ‘init_by_array’ was not declared in this scope 12
ソースコード
#include <iostream> #include <algorithm> #include <sys/time.h> using namespace std; using u64 = unsigned long long; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n; public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}}; const int N = 624; const int M = 397; const unsigned int MATRIX_A = 0x9908b0dfU; const unsigned int UPPER_MASK = 0x80000000U; const unsigned int LOWER_MASK = 0x7fffffffU; static unsigned int mt[N]; static int mti = N + 1; void init_genrand(unsigned int s) { mt[0] = s & 0xffffffffU; for(mti=1; mti<N; mti++) { mt[mti] = (1812433253U * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); mt[mti] &= 0xffffffffU; } } void init_by_array(vector<unsigned int> init_key) { int key_length = init_key.size(); init_genrand(19880731U); // まいぷる int i = 1, j = 0; int k = N > key_length ? N : key_length; for( ; k; k--) { mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525U)) + init_key[j] + j; mt[i] &= 0xffffffffU; i++; j++; if(i >= N) { mt[0] = mt[N-1]; i = 1; } if(j >= key_length) { j = 0; } } for(k=N-1; k; k--) { mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941U)) - i; mt[i] &= 0xffffffffU; i++; if(i >= N) { mt[0] = mt[N-1]; i = 1; } } mt[0] = 0x80000000U; } unsigned int genrand_int32(void) { unsigned int y; static unsigned int mag01[2] = {0x0U, MATRIX_A}; if(mti >= N) { if(mti == N + 1) { init_genrand(5489U); } int kk; for(kk=0; kk<N-M; kk++) { y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK); mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1U]; } for(; kk<N-1; kk++) { y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK); mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1U]; } y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK); mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1U]; mti = 0; } y = mt[mti++]; y ^= (y >> 11); y ^= (y << 7) & 0x9d2c5680U; y ^= (y << 15) & 0xefc60000U; y ^= (y >> 18); return y; } int genrand_int31(void) { return (int)(genrand_int32() >> 1); } double genrand_real2(void) { return genrand_int32()*(1.0/4294967296.0); } // knuth shuffle template<class T> void shuffle(vector<T> &v) { int n = v.size(); for(unsigned int i=n-1; i>=1; --i) { unsigned int k = genrand_int32() % (i + 1); if(k == i) { continue; } swap(v[k], v[i]); } } unsigned long long get_hash(string s, unsigned long long a, unsigned long long b){ unsigned long long hash = 0; for(int i = 0; i < s.size(); i++){ hash = (hash * a + s[i]) % b; } return hash; } const string letters = "abcdefghijklmnopqrstuvwxyz"; string generate(int n) { string res; for(int i : range(n)) { res += letters[genrand_int31() % 26]; } return res; } int main(void) { timeval tval; gettimeofday(&tval, NULL); vector<unsigned int> init; init.push_back(0x123); init.push_back(0x234); init.push_back(0x345); init.push_back(0x456); init.push_back(tval.tv_sec); init.push_back(tval.tv_usec); init_by_array(init); int a, b; scanf("%d%d", &a, &b); while(true) { int n = genrand_int31() % 10 + 10; string s = generate(n); string t = generate(n); u64 r1 = get_hash(s, a, b), r2 = get_hash(t, a, b); if(r1 == r2) { puts(s.c_str()); puts(t.c_str()); break; } } return 0; }