QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#313531 | #8141. Digits | PetroTarnavskyi# | RE | 0ms | 20956kb | C++20 | 3.8kb | 2024-01-24 20:24:22 | 2024-01-24 20:24:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 1e9 + 9;
int mult(int a, int b)
{
return (LL) a * b % mod;
}
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
int sub(int a, int b)
{
return a - b >= 0 ? a - b : a - b + mod;
}
void updAdd(int& a, int b)
{
a += b;
if(a >= mod)
a -= mod;
}
const int N = 174;
//[l, r)
string s[N][N];
//[l, r), [isRight][pos][left]
int dp[N][N][2][N][9];
void solve()
{
int n;
cin >> n;
VI a(n);
FOR(i, 0, n)
cin >> a[i];
FOR(l, 0, n)
{
int sum = 0;
FOR(r, l, n + 1)
{
if(r == l)
s[l][r] = "";
else
s[l][r] = to_string(sum);
if(r != n)
sum += a[r];
}
}
FOR(l, 0, n)
FOR(r, l, n + 1)
FOR(k, 0, 2)
FOR(pos, 0, n + 1)
FOR(len, 0, 9)
dp[l][r][k][pos][len] = 0;
dp[0][n][0][0][0] = 1;
FOR(l, 0, n)
{
RFOR(r, n + 1, l)
{
FOR(pos, 0, n + 1)
{
FOR(len, 0, 9)
{
//isRight = 0;
//cerr << "order " << l << " " << r << " " << pos << " " << len << endl;
if(dp[l][r][0][pos][len] != 0)
{
int val = dp[l][r][0][pos][len];
//cout << "here1 " << l << " " << r << " " << 0 << " " << pos << " " << len << endl;
FOR(k, l, r)
{
if(SZ(s[k][r]) > len)
{
string L = s[pos][l].substr(SZ(s[pos][l]) - len, len);
string R = s[k][r].substr(SZ(s[k][r]) - len, len);
reverse(ALL(L));
if(L == R)
{
updAdd(dp[l][k][1][r][SZ(s[k][r]) - len], val);
// cerr << l << " " << k << " " << 1 << " " << r << " " << SZ(s[k][r]) << " " << len << " " << val << endl;
}
continue;
}
else
{
string L = s[pos][l].substr(SZ(s[pos][len]) - len, SZ(s[k][r]));
string R = s[k][r];
reverse(ALL(L));
if(L == R)
updAdd(dp[l][k][0][pos][len - SZ(s[k][r])], val);
continue;
}
}
}
//isRight = 1
if(dp[l][r][1][pos][len] != 0)
{
int val = dp[l][r][1][pos][len];
//cout << "here2 " << l << " " << r << " " << 1 << " " << pos << " " << len << endl;
FOR(k, l + 1, r + 1)
{
if(SZ(s[l][k]) >= len)
{
string L = s[r][pos].substr(0, len);
string R = s[l][k].substr(0, len);
reverse(ALL(L));
if(L == R)
updAdd(dp[k][r][0][l][SZ(s[l][k]) - len], val);
continue;
}
else
{
string L = s[r][pos].substr(len - SZ(s[l][k]), SZ(s[l][k]));
string R = s[l][k];
reverse(ALL(L));
if(L == R)
updAdd(dp[k][r][1][pos][len - SZ(s[l][k])], val);
continue;
}
}
}
}
}
}
}
int ans = 0;
FOR(l, 0, n)
FOR(k, 0, 2)
FOR(pos, 0, n + 1)
FOR(len, 0, 9)
{
if(dp[l][l][k][pos][len] == 0)
continue;
string cur;
if(k == 0)
{
cur = s[pos][l].substr(SZ(s[pos][l]) - len, len);
}
else
{
cur = s[l][pos].substr(0, len);
}
string rcur = cur;
reverse(ALL(rcur));
if(rcur == cur)
updAdd(ans, dp[l][l][k][pos][len]);
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 20956kb
input:
5 2 123456 654321 5 0 0 0 0 0 6 1 1 1 1 1 1 7 1 1 4 5 1 4 1 9 1 2 3 1 1 1 2 1 1
output:
2 16 8 4 6
result:
ok 5 number(s): "2 16 8 4 6"
Test #2:
score: -100
Runtime Error
input:
13 7 0 0 4 2 3 3 0 12 3 2 1 0 1 4 3 1 4 4 1 1 12 1 1 2 4 2 4 4 4 4 2 4 1 11 2 0 3 3 3 2 4 1 4 2 4 8 2 3 3 3 3 3 1 4 13 1 2 3 1 1 4 4 0 2 2 1 3 0 6 3 2 1 0 3 4 13 4 0 0 2 4 2 0 2 3 4 1 0 2 12 0 4 0 3 1 1 1 2 2 1 4 0 9 4 1 0 2 4 2 0 0 0 11 0 3 2 0 4 3 1 0 0 3 2 12 0 1 0 1 3 1 2 1 1 0 2 1 12 4 2 2 1 4 ...