제출 #1179707

#제출 시각아이디문제언어결과실행 시간메모리
1179707khusanov45Ancient Machine (JOI21_ancient_machine)C++17
5 / 100
13 ms1216 KiB
#include "Anna.h" #include <vector> #include <iostream> using namespace std; #define ll long long bool DEBUG1 = false; namespace { vector<ll> fib; void initFib() { fib.push_back(0); fib.push_back(1); for (int i = 2; i <= 66; ++i){ fib.push_back(fib[i-2] + fib[i-1]); } } ll handleArray(string& b, int l, int r) { ll score = 0; for (int i = l; i < r; ++i){ score += ((ll)b[i]) * fib[r-i]; } return score; } void sendSignals(ll x){ //cout << ": "; for (int i = 49; i >= 0; --i){ //cout << ((x >> i) & 1); Send((x >> i) & 1); } //cout << endl; } } void Anna(int N, vector<char> S) { initFib(); int len = ((N + 63) / 64)*64; string b(len, 0); int i = -1; while (++i < N && S[i] != 'X'); if (i == N){ Send(1); return; } b[i++] = 1; for (; i < N; ++i){ if (i + 1 < N && S[i] == S[i+1]){ continue; } b[i] = (S[i] == 'Z')?1:0; } // cout << b.size() << endl; // int counter = 0; // for (auto x : b){ // cout << (int) x; // ++counter; // if (counter % 64 == 0){ // cout << endl; // } // } // cout << endl; auto hashValue = std::hash<std::string>{}(b); for (int i = 0; i != 64; ++i){ Send((hashValue >> i) & 1); } if (DEBUG1) std::cout << "sent hash " << hashValue << endl; for (int l = 0; l < N; l += 64){ ll permutation = handleArray(b, l, l+64); //cout << permutation; sendSignals(permutation); } }
#include "Bruno.h" #include <vector> #include <iostream> using namespace std; #define ll long long bool DEBUG = false; namespace { vector<ll> fib; void initFib() { fib.push_back(0); fib.push_back(1); for (int i = 2; i <= 66; ++i){ fib.push_back(fib[i-2] + fib[i-1]); } } ll getNumber(vector<int> & a, int start){ ll ans = 0; for (int i = start; i < start + 50; ++i){ ans <<= 1; ans += a[i]; } return ans; } void deriveSequence(ll number, string & result){ for (int i = 64; i >= 1; --i){ if (fib[i] <= number){ number -= fib[i]; result += char(1); } else{ result += char(0); } //cout << result.back(); } //cout << endl; } } void Bruno(int N, int L, std::vector<int> A) { if (L == 1){ for (int i = 0; i < N; ++i){ Remove(i); } return; } initFib(); // for (auto & it : A){ // cout << it; // } // cout << endl; std::size_t hashValue = 0; for (int i = 0; i != 64; ++i){ hashValue |= ((size_t)A[i] << i); } string result; for (int l = 64; l < L; l += 50){ ll number = getNumber(A, l); deriveSequence(number, result); } if (DEBUG) { std::cout << "get hash = " << hashValue << endl; for (int i = 0; i != 64; ++i){ std::cout << A[63-i]; } cout << endl; for (char c : result){ cout << int(c); } cout << endl; } size_t getHash = std::hash<std::string>{}(result); if (DEBUG) cout << "Cal hash = " << getHash << endl; if (getHash != hashValue){ Remove(-1); } vector<int> ones; for (int i = 0; i < result.size(); ++i){ if (result[i] == 1){ ones.push_back(i); } } // PreX for (int i =0; i != ones.front();++i){ Remove(i); } for (int i = 1; i < ones.size(); ++i){ for (int j = ones[i]-1; j > ones[i-1]; --j){ Remove(j); } Remove(ones[i]); } Remove(ones[0]); // cout << ones.back()+1 << endl; // cout << N << endl; for (int j = ones.back()+1; j < N; ++j){ Remove(j); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...