QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#114923#5474. Incredibly Cute Penguin ChicksNicolas125841ML 22ms206156kbC++141.8kb2023-06-24 07:44:142023-06-24 07:44:16

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-24 07:44:16]
  • 评测
  • 测评结果:ML
  • 用时:22ms
  • 内存:206156kb
  • [2023-06-24 07:44:14]
  • 提交

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";
}

详细

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...

output:


result: