QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308936 | #8129. Binary Sequence | ucup-team087# | AC ✓ | 123ms | 14520kb | C++14 | 3.0kb | 2024-01-20 13:52:02 | 2024-01-20 13:52:02 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
constexpr int LIM = 1001001;
constexpr int SMALL = 80;
// https://www.njohnston.ca/2010/11/the-binary-look-and-say-sequence/
constexpr int U = 10;
string S[U] = {"1", "11", "10", "110", "1110", "11110", "100", "1100", "11100", "111100"};
int L[U] = {0, 3, 0, 3, 0, 7, 0, 3, 0, 7};
int R[U] = {2, 1, 5, 4, 6, 4, 9, 8, 10, 8};
int INI[U] = {1, 2, 2, 3, 4, 5, 3, 4, 5, 6};
int dp[SMALL + 1][U];
bitset<LIM> brt[SMALL + 1];
int main() {
for (int u = 0; u < U; ++u) {
--L[u];
--R[u];
dp[0][u] = INI[u];
}
for (int n = 1; n <= SMALL; ++n) {
for (int u = 0; u < U; ++u) {
dp[n][u] = min(((~L[u]) ? dp[n - 1][L[u]] : 0) + dp[n - 1][R[u]], LIM);
}
// cerr<<"dp["<<n<<"] = ";pv(dp[n],dp[n]+U);
}
{
vector<int> crt{0};
for (int n = 0; n <= SMALL; ++n) {
int len = 0;
vector<int> nxt;
for (const int u : crt) {
nxt.push_back(R[u]);
if (~L[u]) nxt.push_back(L[u]);
for (int x = S[u].size(); --x >= 0; ) {
brt[n][len++] = S[u][x] - '0';
if (len == LIM) goto done;
}
}
done:{}
// cerr<<n<<": "<<len<<"; ";for(int i=0;i<len&&i<100;++i)cerr<<brt[n][i];cerr<<endl;
assert(len == dp[n][0]);
crt.swap(nxt);
}
}
assert(brt[SMALL - 0] == brt[SMALL - 2]);
assert(brt[SMALL - 1] == brt[SMALL - 3]);
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
Int N;
int M;
scanf("%lld%d", &N, &M);
--N;
if (N >= SMALL - 1) {
N = (SMALL - 1) + (N - (SMALL - 1)) % 2;
}
int ans = 0;
if (M < dp[N][0]) {
ans = brt[N][M];
}
printf("%d\n", ans);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 106ms
memory: 14520kb
input:
10 4 0 4 1 4 2 4 3 4 4 4 5 4 6 6 3 6 7 118999881999119725 3
output:
1 1 0 1 1 1 0 1 1 0
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 111ms
memory: 14208kb
input:
10 28 69772 10 7908 4 3198 4 85913 14 52729 3 20445 9 88912 17 23743 25 37356 2 97697
output:
0 0 0 0 0 0 0 0 0 0
result:
ok 10 numbers
Test #3:
score: 0
Accepted
time: 110ms
memory: 14232kb
input:
100 29 110358 18 13645 18 590344 36 550462 11 133055 8 769352 11 265432 7 158530 12 29189 2 830361 11 584395 31 693707 7 879812 19 25069 21 616926 3 85158 31 675739 17 118385 24 315535 29 59615 10 33445 17 609235 8 738138 20 209540 4 287616 32 522302 26 959741 5 453537 27 74313 28 296289 28 857972 2...
output:
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 123ms
memory: 14264kb
input:
100000 702433635413308636 962533 864089450531108488 538792 262747333715821506 454514 859830947243984718 105219 365621373252206174 447331 890829905503831899 507146 116987306031929573 154370 157986473366693144 364746 502917586764426513 49981 874588963478161584 594867 467219058104100510 790503 11034861...
output:
1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 ...
result:
ok 100000 numbers
Extra Test:
score: 0
Extra Test Passed