QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114923 | #5474. Incredibly Cute Penguin Chicks | Nicolas125841 | ML | 22ms | 206156kb | C++14 | 1.8kb | 2023-06-24 07:44:14 | 2023-06-24 07:44:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ll mod = 998244353;
struct FT {
vector<ll> s;
FT() : s(2000001) {}
FT(int n) : s(n) {}
void update(int pos, ll dif) { // a [ pos ] += d i f
for (; pos < sz(s); pos |= pos + 1) s[pos] = (s[pos] + dif) % mod;
}
ll query(int pos) { // sum of values in [0 , pos)
ll res = 0;
for (; pos > 0; pos &= pos - 1) res = (res + s[pos-1]) % mod;
return res;
}
};
int main(){
cin.tie(NULL)->sync_with_stdio(false);
string s;
cin >> s;
map<int, FT> diag, hori, vert;
diag.insert({1000000, FT(2000001)});
hori.insert({1000000, FT(2000001)});
vert.insert({1000000, FT(2000001)});
diag[1000000].update(1000000, 1);
hori[1000000].update(1000000, 1);
vert[1000000].update(1000000, 1);
int x = 1000000, y = 1000000, yn;
ll val = 0;
for(char c : s){
if(c == 'I')
y++;
else if(c == 'C')
x++;
else{
x--;
y--;
}
yn = y - (x - 1000000);
if(diag.find(yn) == diag.end())
diag.insert({yn, FT(2000001)});
if(hori.find(y) == hori.end())
hori.insert({y, FT(2000001)});
if(vert.find(x) == vert.end())
vert.insert({x, FT(2000001)});
val = diag[yn].query(2000001) + hori[y].query(x) + vert[x].query(y) - diag[yn].query(x + 1);
diag[yn].update(x, val);
hori[y].update(x, val);
vert[x].update(y, val);
//cout << val << "\n";
}
cout << val << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 112344kb
input:
ICPC
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 4ms
memory: 190568kb
input:
CCCIIIPPP
output:
69
result:
ok single line: '69'
Test #3:
score: 0
Accepted
time: 22ms
memory: 206156kb
input:
PICCICCIPPI
output:
24
result:
ok single line: '24'
Test #4:
score: -100
Memory Limit Exceeded
input:
PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...