题解归档 - cf2226A

题解归档 - cf2226A

本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。

思路

cf2226A - Disturbing Distribution

pattern: partition into nondecreasing subsequences with positive products.

claim: values greater than 1 are never cheaper to multiply together, because xy >= x+y for x,y>=2. Thus each >1 value can be paid separately. A value 1 costs nothing if it is placed before some later >1 in that operation; all trailing ones after the last >1 need one separate operation of cost 1. If all values are 1, one operation costs 1.

check: samples [1,2,1,2,3] -> 7, [3,2,1] -> 6, all ones -> 1.

代码

来源:problems/cf2226A/solution.cpp

/* Author: likely
 * Time: 2026-06-27
**/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=676767677;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        int n,last=-1;
        cin>>n;
        ll ans=0;
        vector<int>a(n+1);
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(a[i]>1){
                ans+=a[i];
                last=i;
            }
        }
        if(last==-1){
            cout<<1<<"\n";
            continue;
        }
        if(last<n) ans++;
        cout<<(ans%MOD)<<"\n";
    }
    return 0;
}
~  ~  The   End  ~  ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
文章二维码 分类标签:归档TypechoAutoUpload
文章标题:题解归档 - cf2226A
文章链接:https://www.fangshaonian.cn/archives/239/
最后编辑:2026 年 6 月 28 日 19:05 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 5 + 7 =
快来做第一个评论的人吧~