codeforce div3 506

D. Concatenated Multiples(1029D)

题目链接:http://codeforces.com/contest/1029/problem/D
我咋个想都是 O(n2) O ( n 2 ) 的复杂度T_T,还是太挫了
这道题看懂了之后就是跟以前很经典的一道题一个意思:给 n n 个数,让找出两个数的和等于 K 的对数有几对,以前就是咋个想对数 n2 n 2 的复杂度,结果,别人是直接找某个数的互补的那个数有几个就行了,用map比较方便,这道题的思路也是一样的,只不过变了一下,这道题是说两个数 A,B A , B 要接起来变成 AB A B ,这道题就是找 B B 的互补有几个。

这道题具体做法:预处理每个数后面添加几个0并取模,这样就很方便的找了,比如说找 123 作为 B B ,对 11 取模的个数, 123%11=2 123 % 11 = 2 ,那我就找他互补的 112=9 11 − 2 = 9 ,也就是说找个 A A 后面添加了 3 0 0 取模之后是等于 9 的有几个就行了,而这个是之前预处理出来了的,查找非常快,思路就是酱~

但是这道题。。。。被卡超时卡得很恼火,减少取模次数,然后又改单组,最后靠一个优秀的输入挂刚好过的T_T

#include"bits/stdc++.h"
#define out(x) cout<<#x<<"="<<x
#define C(n,m) (m>n?0:(long long)fac[(n)]*invf[(m)]%MOD*invf[(n)-(m)]%MOD)
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
const int MOD=1e9+7;
map<LL,LL>Mp[20];
LL a[maxn];
LL P[20]={1}; 
namespace fastIO {
    #define BUF_SIZE 100000
    //fread -> read
    bool IOerror = 0;
    inline char nc() {
        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
        if(p1 == pend) {
            p1 = buf;
            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
            if(pend == p1) {
                IOerror = 1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    inline void read(LL &x) {
        char ch;
        while(blank(ch = nc()));
        if(IOerror) return;
        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
    }
    #undef BUF_SIZE
};
using namespace fastIO;
int main()
{
    for(int i=1;i<=15;i++)P[i]=P[i-1]*10;
    LL N,K;
    read(N);
    read(K);
    for(int i=1;i<=N;i++)
    {
        read(a[i]);
        LL t=a[i];
        for(int j=1;j<=10;j++)
        {
            t*=10;
            t%=K;
            Mp[j][t]++;
        }
    }
    LL ans=0;
    for(int i=1;i<=N;i++)
    {
        LL t=a[i]%K;
        int len=log10(a[i])+1;
        ans+=Mp[len][(K-a[i]%K)%K];
        if((t*P[len]+t)%K==0LL)ans--;//减掉自己又当A又当B的情况 
    }
    cout<<ans<<endl;
}
### Codeforces Problem or Contest 998 Information For the specific details on Codeforces problem or contest numbered 998, direct references were not provided within the available citations. However, based on similar structures observed in other contests such as those described where configurations often include constraints like `n` representing numbers of elements with defined ranges[^1], it can be inferred that contest or problem 998 would follow a comparable format. Typically, each Codeforces contest includes several problems labeled from A to F or beyond depending on the round size. Each problem comes with its own set of rules, input/output formats, and constraint descriptions. For instance, some problems specify conditions involving integer inputs for calculations or logical deductions, while others might involve more complex algorithms or data processing tasks[^3]. To find detailed information regarding contest or problem 998 specifically: - Visit the official Codeforces website. - Navigate through past contests until reaching contest 998. - Review individual problem statements under this contest for precise requirements and examples. Additionally, competitive programming platforms usually provide comprehensive documentation alongside community discussions which serve valuable resources when exploring particular challenges or learning algorithmic solutions[^2]. ```cpp // Example C++ code snippet demonstrating how contestants interact with input/output during competitions #include <iostream> using namespace std; int main() { int n; cin >> n; // Process according to problem statement specifics } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值