Triple Attack 题解

直接暴力显然不可行。

我们容易发现,变量 \(T\) 的增量以 \(3\) 为循环,一次循环会造成 \(5\) 的贡献,所以我们容易想到对每个 \(a_i\) 直接对 \(5\) 计算倍数和取余,然后对于余数分类讨论去增加,然后对于倍数部分统一增加即可。

有些细节。

Code

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace std;
// using namespace  __gnu_pbds;
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> tr;//从小到大
// int findnum(int k){auto it=tr.find_by_order(k-1);return ((it!=tr.end())?(*it):1e9+7);}//查元素
// int findrank(int x){return tr.order_of_key(x)+1;}//查排名
static char buf[100000], *pa = buf, *pd = buf;
#define gc pa == pd && (pd = (pa = buf) + fread(buf, 1, 100000, stdin), pa == pd) ? EOF : *pa++
inline int read()
{
	int w = 1, s = 0; char ch = gc;
	while(!isdigit(ch)){if(ch=='-')w=-1;ch=gc;}
	while(isdigit(ch)){s=s*10+(ch-'0');ch=gc;}
	return w*s;
}
const int mod=998244353;
const int maxn=1e6+10;
const int inf=1e9+7;
int n,m,a[maxn],b[maxn];
string s,t;
int ans,sum;

signed main()
{
#ifdef Lydic
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
// #else
    // freopen("direct.in","r",stdin);
    // freopen("direct.out","w",stdout);
#endif
    cin>>n;
    for(int i=1;i<=n;i++)a[i]=read();
    int t=1;
    for(int i=1;i<=n;i++)
    {
        if(t%3==1)
        {
            a[i]--;t++;
            if(a[i]<=0)continue;
            a[i]--;t++;
            if(a[i]<=0)continue;
        }
        else if(t%3==2)
        {
            a[i]--;t++;
            if(a[i]<=0)continue;
        }
        // cout<<a[i]<<' '<<t<<endl;
        int d=a[i]/5,k=a[i]%5;
        if(k==0)
        {
            t+=d*3;
            continue;
        }
        if(k<=3)t++;
        else if(k==4)t+=2;
        t+=d*3;
    }
    cout<<t-1;
    return 0;
}
posted @ 2024-08-25 16:11  Redamancy_Lydic  阅读(2)  评论(0编辑  收藏  举报