QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487006 | #5346. Binary Tree | PetroTarnavskyi# | WA | 51ms | 4820kb | C++20 | 1.8kb | 2024-07-22 15:05:54 | 2024-07-22 15:05:54 |
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 = 21092013;
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
int mult(int a, int b)
{
return (LL)a * b % mod;
}
int binpow(int a, int p)
{
int ans = 1;
while (p)
{
if (p & 1) ans = mult(ans, a);
a = mult(a, a);
p /= 2;
}
return ans;
}
void solve()
{
string S, t;
cin >> S >> t;
string s = "";
FOR (i, 0, SZ(S))
{
if (S[i] == 'U')
{
if (!s.empty())
s.pop_back();
}
else
s.PB(S[i]);
}
int n = SZ(t);
VI l(n), r(n), u(n);
FOR (i, 0, n)
{
if (t[i] == 'L')
l[i] = 1;
if (t[i] == 'R')
r[i] = 1;
if (t[i] == 'U')
u[i] = 1;
if (i)
{
u[i] += u[i - 1];
l[i] += l[i - 1];
r[i] += r[i - 1];
}
}
int ans = 0;
FOR (cnt, 1, SZ(s) + 1)
{
int j = lower_bound(ALL(u), cnt) - u.begin();
if (j == n)
break;
ans = add(ans, 1);
if (s[SZ(s) - cnt] == 'R')
j = lower_bound(ALL(l), l[j] + 1) - l.begin();
else
j = lower_bound(ALL(r), r[j] + 1) - r.begin();
if (j == n)
continue;
int pw = l[n - 1] - l[j] + r[n - 1] - r[j];
ans = add(ans, binpow(2, pw));
}
int pw = l[n - 1] + r[n - 1];
ans = add(ans, binpow(2, pw));
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
FOR (tc, 0, t)
{
cout << "Case " << tc + 1 << ": ";
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
input:
2 L LU L L
output:
Case 1: 3 Case 2: 2
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 51ms
memory: 4820kb
input:
15 LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL...
output:
Case 1: 5358778 Case 2: 7619357 Case 3: 21 Case 4: 14140136 Case 5: 5089192 Case 6: 16027387 Case 7: 2415909 Case 8: 5205350 Case 9: 16170279 Case 10: 13700498 Case 11: 15921269 Case 12: 13966137 Case 13: 13839199 Case 14: 2991407 Case 15: 6748642
result:
wrong answer 1st lines differ - expected: 'Case 1: 5382631', found: 'Case 1: 5358778'