coeforce---Submarine in the Rybinsk Sea

地址:
easy:https://codeforces.com/contest/1195/problem/D
因为每个数的长度相同,所以每个数的每个位对答案的贡献是在答案的2k位,2k-1位

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const LL mod = 998244353;
const int N = 1e5 + 5;
 
LL a[N];
 
LL solve(LL x)
{
    LL res = 0;
    LL index = 1;
    while(x){
        LL r = x % 10LL;
        res = (res + index * 11LL % mod * r % mod) % mod;
        x /= 10LL;
        index = index * 100LL % mod;
    }
    return res % mod;
}
 
int main()
{
    int n;
    scanf("%d",&n);
    LL ans = 0;
    for(int i = 0;i < n;++i){
        scanf("%lld",&a[i]);
        ans = (ans + solve(a[i])) % mod;
    }
    printf("%lld\n",ans * n * 1LL % mod);
    return 0;
}

hard: https://codeforces.com/contest/1195/problem/D2

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1e5 + 5;
const LL mod = 998244353;

LL val[55],pow10[55];
LL len[N],n;

LL solve(LL x)
{
    int cnt = 0;
    while(x){
        val[cnt + 1] += x % 10LL;
        x /= 10LL;
        cnt++;
    }
    return cnt;
}

int main()
{
    memset(val,0,sizeof(val));
    scanf("%lld",&n);
    for(int i = 1;i <= n;++i){
        LL x;
        scanf("%lld",&x);
        len[i] = solve(x);
    }
    pow10[0] = 1;
    for(int i = 1;i <= 21;++i){
        pow10[i] = 10LL * pow10[i - 1] % mod;
    }
    LL ans = 0;
    for(int j = 10;j >= 1;--j){  //讨论所有数的第j位和,对每个数来说会产生的贡献
        for(int i = 1;i <= n;++i){
            if(len[i] >= j){
                //当j小于等于当前对比的数的长度,那第j位和产生对答案的贡献是对2*k位和2*k-1位
                ans = (ans + pow10[(j - 1) * 2] * 11LL % mod * val[j] % mod) % mod;
            }else{
                //当j大于当前对比的数的长度,那第j位和产生对答案的贡献是len[i]+ j - 1位
                ans = (ans + pow10[len[i] + j - 1] * 2LL % mod * val[j] % mod) % mod;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值