acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 题解

    userId_undefined

    法兰西玫瑰

    倔强青铜
    19阅读
    0回复
    0点赞
  • 题解

    好家伙,时间内存又击败了两位大佬

    userId_undefined

    zhouty

    秩序白银
    1阅读
    0回复
    0点赞
  • !

    #include<bits/stdc++.h> using namespace std; const int N = 300002; int n, k, pre[N], dp[N]; struct node { int num, id; bool operator < (const node &t) const { if(num == t.num) return pre[id] < pre[t.id]; return num > t.num; } }; priority_queue <node> q; int main() { char ch; scanf("%d %d", &n, &k); scanf("\n"); for(int i = 1; i <= n; i ++) { ch = getchar(); if(ch == 'G') pre[i] = pre[i - 1] + 1; else pre[i] = pre[i - 1] - 1; } q.push((node) {0, 0}); for(int i = 1; i <= n; i ++) { while(q.top().id < i - k) q.pop(); dp[i] = (pre[i] >= pre[q.top().id]) ? q.top().num + 1 : q.top().num; q.push((node) {dp[i], i}); } printf("%d\n", dp[n]); return 0; }

    userId_undefined

    ^

    倔强青铜
    0阅读
    0回复
    0点赞
首页