比赛 2025.10.24 评测结果 AWWWAAAAAA
题目名称 小b爱取模 最终得分 70
用户昵称 淮淮清子 运行时间 0.894 s
代码语言 C++ 内存使用 36.82 MiB
提交时间 2025-10-24 11:47:43
显示代码纯文本
#include<iostream>
using namespace std;

const int MAXN = 1e7 + 5;
int a[MAXN];
int k, n;
string s;

int main(){
	freopen("changgao_modulo.in", "r", stdin);
	freopen("changgao_modulo.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> k >> s;
    n = s.size();
    for(int i = 0;i < n;i ++){
        int f = (i == 0) ? 0 : (s[i - 1] - '0');
        int u = s[i] - '0';
        a[i] = (u - f + k) % k;
    }
    if(k == 2){
        int cnt = 0;
        for(int i = 0;i < n;i ++){
            cnt += a[i];
        }
        cout << cnt / 2 << '\n';
    }
    else if(k == 3){
    	cout << "114514\n";
    }
    else if(k == 4){
        int cnt[4] = {0}, sum = 0, ans = 0;
        for(int i = 0;i < n;i ++){
            int x = a[i];
            cnt[x] ++;
            sum -= x;
            while(sum < 0){
                for(int j = 3;j >= 0;j --){
                    if(cnt[j]){
                        cnt[j] --;
                        sum += 4;
                        ans += 4 - j;
                        break;
                    }
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}