Submission #1295204

#TimeUsernameProblemLanguageResultExecution timeMemory
1295204NValchanovAncient Machine (JOI21_ancient_machine)C++20
5 / 100
36 ms6312 KiB
#include "Anna.h" #include <vector> #include <stack> #include <algorithm> #include <cassert> #include <iostream> #define ulong unsigned long long int using namespace std; const int MAXN = 1e5 + 10; const int BLOCK_SIZE = 63; const int MAXBITS = 44; namespace { ulong f[BLOCK_SIZE + 2 + 1]; ulong encode(vector < bool > v) { reverse(v.begin(), v.end()); ulong result = 0; for(int i = 0; i < BLOCK_SIZE; i++) { if(v[i]) result += f[i]; } return result; } void fill_f() { f[0] = 1; f[1] = 1; for(int i = 2; i <= BLOCK_SIZE + 2; i++) { f[i] = f[i - 1] + f[i - 2]; } } } void Anna(int n, vector<char> s) { fill_f(); vector < bool > red(n, false); stack < int > st; bool lampa = false; for(int i = 0; i < n; i++) { if(s[i] == 'X') { red[i] = !lampa; lampa = true; } else if(s[i] == 'Y') { red[i] = false; } else if(s[i] == 'Z') { if(!lampa) { red[i] = false; } else if(i == n - 1) { red[i] = true; } else if(s[i + 1] != 'Z') { red[i] = true; } else { red[i] = false; } } } assert(red.size() == n); while(red.size() % BLOCK_SIZE != 0) { red.push_back(0); } int sz = red.size(); for(int i = 0; i < sz; i += BLOCK_SIZE) { vector < bool > tmp; for(int j = 0; j < BLOCK_SIZE; j++) { tmp.push_back(red[i + j]); } ulong type = encode(tmp); for(int j = 0; j < MAXBITS; j++) { if(type >> j & 1) { Send(1); } else { Send(0); } } } }
#include "Bruno.h" #include <vector> #include <algorithm> #include <stack> #include <iostream> #include <cassert> #define ulong unsigned long long int using namespace std; const int MAXN = 1e5 + 10; const int BLOCK_SIZE = 63; const int MAXBITS = 44; namespace { vector < int > red; ulong f[BLOCK_SIZE + 2 + 1]; void fill_f() { f[0] = 1; f[1] = 1; for(int i = 2; i <= BLOCK_SIZE + 2; i++) { f[i] = f[i - 1] + f[i - 2]; } } vector < bool > decode(ulong x) { vector < bool > result; for(int i = BLOCK_SIZE - 1; i >= 0; i--) { if(x >= f[i]) { x -= f[i]; result.push_back(1); } else { result.push_back(0); } } return result; } } void Bruno(int n, int l, vector < int > a) { fill_f(); vector < bool > red; if(a.size() % MAXBITS != 0) { int ax = 0; while(1) { ax++; } } for(int i = 0; i < l; i += MAXBITS) { ulong type = 0; for(int j = 0; j < MAXBITS; j++) { if(a[i + j]) { type += (1LL << j); } } vector < bool > tmp = decode(type); for(bool b : tmp) { if(red.size() == n) break; red.push_back(b); } } assert(red.size() == n); stack < int > st; for(int i = 0; i < n; i++) { if(red[i]) { if(st.empty()) { st.push(i); } else { while(st.size() >= 2) { int p = st.top(); st.pop(); Remove(p); } Remove(i); } } else { if(st.empty()) { Remove(i); } else { st.push(i); } } } while(!st.empty()) { int p = st.top(); st.pop(); Remove(p); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...