QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#343053 | #8251. Missing Number | ElTeeran_ElHayga# | WA | 17ms | 5688kb | C++20 | 2.5kb | 2024-03-01 21:32:02 | 2024-03-01 21:32:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define fi first
#define se second
#define pp push_back
#define all(x) (x).begin(), (x).end()
#define Ones(n) __builtin_popcount(n)
#define endl '\n'
#define mem(arrr, xx) memset(arrr,xx,sizeof arrr)
//#define int long long
#define debug(x) cout << (#x) << " = " << x << endl
void Gamal() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Clion
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}
int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};
int dy[] = {-1, +1, +0, +0, +1, -1, +1, -1};
const double EPS = 1e-9;
const ll OO = 0X3F3F3F3F3F3F3F3F;
const int N = 5e5 + 5, INF = INT_MAX, MOD = 1e9 + 7, LOG = 20;
int dp[N][6][2], vis[N][6][2],vis2[N][6][2], vid;
string s;
set<int>ans;
int slv(int i,int lst,bool skip,int num){
if(i == s.size()){
return 1;
}
int &ret = dp[i][lst][skip];
if(vis[i][lst][skip] == vid)
return ret;
vis[i][lst][skip] = vid;
ret = 0;
if(!skip)ret = slv(i,0,1,num + 1);
int cur = 0;
for (int j = i; j < min(i + 5,(int)s.size()); ++j) {
cur = cur * 10 + s[j] - '0';
if(!cur)break;
if(cur == num + 1 || num < 1){
ret |= slv(j + 1,j - i + 1,skip,cur);
}
}
return ret;
}
void build(int i,int lst,bool skip,int num){
if(i == s.size()){
ans.insert(num);
return;
}
if(vis2[i][lst][skip] == vid)
return;
vis2[i][lst][skip] = vid;
int op = slv(i,lst,skip,num);
if(!op)return;
if(!skip && slv(i,0,1,num + 1)){
build(i,0,1,num + 1);
}
int cur = 0;
for (int j = i; j < min(i + 5,(int)s.size()); ++j) {
cur = cur * 10 + s[j] - '0';
if(!cur)break;
if(cur == num + 1 || num < 1){
if(skip){
if(slv(j + 1,j - i + 1,skip,cur) && cur > 1)ans.insert(cur - 1);
}
else if(slv(j + 1,j - i + 1,skip,cur))
build(j + 1,j - i + 1,skip,cur);
}
}
}
void solve() {
++vid;
ans.clear();
cin >> s;
build(0, 0, false,-1e9);
cout << ans.size() << endl;
for(auto x:ans)cout << x << " ";
cout << endl;
}
signed main() {
Gamal();
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5616kb
input:
1 891112
output:
1 10
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 17ms
memory: 5688kb
input:
31408 787187871978720787217872278723787247872678727 8787287874878758787687877 834918349283493834958349683497 295982959929600296012960229604 602160226023602460256027602860296030 504545045550456504575045850459504605046250463 17937179381794017941 5226152262522635226552266 304693047030471304733047430475...
output:
1 78725 1 87873 1 83494 1 29603 1 6026 1 50461 1 17939 1 52264 1 30472 1 71484 1 44832 1 88042 1 75634 1 63756 1 65055 1 66515 1 26238 1 29009 1 45270 1 11194 1 75204 1 74784 1 72747 1 29546 1 81791 1 11504 1 73091 1 15640 1 36200 1 47814 1 82261 1 3667 1 6949 1 8171...
result:
wrong answer 212th lines differ - expected: '49804 49806', found: '49804 49805 '