#12TLE了83ms,求卡常
查看原帖
#12TLE了83ms,求卡常
1074084
asd890123楼主2024/7/12 12:31
#include <iostream>

using namespace std;

const int N = 50005;

int a[N];
long s[N];

signed main(){
    
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    
    int n,ans = 0;
    
    cin >> n;
    for (int i = 1;i <= n;i++) cin >> a[i],s[i] = s[i - 1] + a[i];
    for (int i = n;i;i--)
        for (int j = 1;j <= i - ans;j++)
            if ((s[i] - s[j - 1]) % 7 == 0){
                
                ans = i - j + 1;
                break;
                
            }
    cout << ans << '\n';
    
    return 0;
}

据我所知,700ms才停止记时,所以583ms应该是准的

2024/7/12 12:31
加载中...