QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#263371 | #5414. Stop, Yesterday Please No More | KhNURE_KIVI# | WA | 5ms | 3556kb | C++20 | 4.3kb | 2023-11-24 19:39:48 | 2023-11-24 19:39:48 |
Judging History
answer
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#ifdef LOCAL
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
#else
#include <bits/stdc++.h>
#endif
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
inline bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
inline bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef LOCAL
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif // LOCAL
const int max_n = -1, inf = 1000111222;
inline void test_case () {
int n, m, k;
cin >> n >> m >> k;
string s;
cin >> s;
int X[2] = {}, Y[2] = {}, x = 0, y = 0;
for (auto &i : s) {
if (i == 'U') {
x -= 1;
}
else if (i == 'D') {
x += 1;
}
else if (i == 'L') {
y -= 1;
}
else {
assert(i == 'R');
y += 1;
}
umax(X[1], x);
umin(X[0], x);
umax(Y[1], y);
umin(Y[0], y);
}
int lx = -X[0];
int ly = -Y[0];
int rx = n - 1 - X[1];
int ry = m - 1 - Y[1];
if (lx > rx || ly > ry) {
if (k == 0) {
cout << n * m << '\n';
}
else {
cout << "0\n";
}
return;
}
int ans = 0;
x = y = 0;
vector <pii> have;
have.reserve(len(s) + 1);
have.pb({0, 0});
for (auto &i : s) {
if (i == 'U') {
x -= 1;
}
else if (i == 'D') {
x += 1;
}
else if (i == 'L') {
y -= 1;
}
else {
assert(i == 'R');
y += 1;
}
have.pb({x, y});
}
sort(all(have));
have.erase(unique(all(have)), have.end());
vector <vector <int> > a(n + 1, vector <int> (m + 1));
auto add = [&] (int cx, int cy, int val) {
umax(cx, 0);
umax(cy, 0);
umin(cx, n);
umin(cy, m);
a[cx][cy] += val;
};
for (auto &i : have) {
int xx, yy;
tie(xx, yy) = i;
add(xx + lx, yy + ly, 1);
add(xx + rx + 1, yy + ry + 1, 1);
add(xx + rx + 1, yy + ly, -1);
add(xx + lx, yy + ry + 1, -1);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i) {
a[i][j] += a[i - 1][j];
}
if (j) {
a[i][j] += a[i][j - 1];
}
if (i && j) {
a[i][j] -= a[i - 1][j - 1];
}
}
}
int now = (rx - lx + 1) * (ry - ly + 1);
LOG(now, n, m, k);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m - 1; j++) {
int alive = now - a[i][j];
if (alive == k) {
++ans;
}
}
}
cout << ans << '\n';
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for (int test = 1; test <= t; test++) {
test_case();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3376kb
input:
3 4 5 3 ULDDRR 4 5 0 UUUUUUU 4 5 10 UUUUUUU
output:
2 20 0
result:
ok 3 number(s): "2 20 0"
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 3556kb
input:
1060 19 12 0 UDLDDUUUUDDDLLRDUDUURULUUUDRDUDRDRLRLRLULULLLDLDDRLUUUURUUUDDRLLRUUUDULURUULLRDRLRDDURDUUURRRLURLRUULRRUDURDLUUURDLURDDLUUURDDRLLURRDLRUDLRDRLLRRDRDDLDRURRRLUDULLLRUUDLRRURRDLLRRRDLLRDDDLRLRURURDDDL 11 1 0 UR 3 18 33 UDRLR 17 11 132 RLDRDLDRUU 6 10 13 UULUDDLRDLUUDLDD 1 15 0 D 6 20 50 D...
output:
228 11 18 99 16 15 34 240 9 0 0 11 14 18 26 16 1 19 108 6 1 1 0 6 0 28 16 19 0 1 10 9 15 5 320 9 7 0 0 0 12 0 11 0 0 12 0 22 36 51 23 7 6 2 2 48 28 8 63 11 49 13 10 2 108 10 16 44 0 3 9 0 4 30 14 99 105 10 14 17 0 66 8 11 28 39 32 42 30 9 56 90 14 0 121 3 48 29 36 11 0 30 5 3 3 7 16 40 20 32 0 37 0 ...
result:
wrong answer 3rd numbers differ - expected: '20', found: '18'