QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#714202#8340. 3 SumStoneXie#RE 0ms3512kbC++172.8kb2024-11-05 22:03:092024-11-05 22:03:10

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 22:03:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3512kb
  • [2024-11-05 22:03:09]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define unmap unordered_map
#define unset unordered_set
#define MAXQ priority_queue
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define frep(i,a,b) for(int i=a;i<(b);++i)
using namespace std;
template<typename T> using MINQ=priority_queue<T,vector<T>,greater<T> >;
using pii=pair<int,int>;
using vi=vector<int>;
using vii=vector<vi>;
const int siz=4,N=305;
int n,K;
array<int,4> MOD;
void myrand() {
    random_device rd;
    mt19937 gen(rd());
    uniform_int_distribution<long long> dis(1e7, 1e9);
    for (int i = 0; i < siz; ++i) MOD[i]=dis(gen);
}
array<int,siz> num[N],M[4];
vi trans(string &s) {
    vi res;
    for(auto c:s) {
        res.push_back(c-'0');
    }
    reverse(res.begin(),res.end());
    while((int)res.size()>K) {
         for(int i=(int)res.size()-1;i>=K;i--) {
             res[i-K]+=res[i];
             res.pop_back();
         }
        for(int i=0;i<(int)res.size();i++) {
            if(res[i]>=10) {
                int x=res[i]/10;
                res[i]%=10;
                if(i==(int)res.size()-1) res.push_back(x);
                else res[i+1]+=x;
            }
        }
    }
    return res;
}
array<int,siz> cal(vi &vec) {
    array<int,4> res={};
    reverse(vec.begin(),vec.end());
    for(auto x:vec)
        for(int i=0;i<siz;i++)
            res[i]=(res[i]*10+x)%MOD[i];
    return res;
}
void getM() {
    vi res(K,9);
    M[1]=cal(res);
    for(int r=2;r<=3;r++) {
        for(int j=0;j<K;j++) res[j]+=9;
        for(int i=0;i<(int)(res.size());i++) {
            if(res[i]>=10) {
                int x=res[i]/10;
                res[i]%=10;
                if(i==(int)(res.size())-1) res.push_back(x);
                else res[i+1]+=x;
            }
        }
        M[r]=cal(res);
    }
}
void solve(){
    myrand();
    cin>>n>>K;
    for(int i=1;i<=n;i++) {
        string s;
        cin>>s;
        auto vec=trans(s);
        num[i]=cal(vec);
    }
    getM();
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
            for(int k=j;k<=n;k++) {
                array<int,siz> tmp={};
                for(int ii=0;ii<siz;ii++) {
                    tmp[ii]=(num[i][ii]+num[j][ii]+num[k][ii])%MOD[ii];
                }
                for(auto mm : M) {
                    if(tmp==mm) {
                        ans++;
                        break;
                    }
                }
            }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int _t=1;
    //	cin>>_t;
    //	cout<<fixed<<setprecision(20);
    for(int i=1;i<=_t;i++){
        //cout<<"Case "<<i<<": ";
        solve();
    }
    return 0;
}
/*
4 1
0
1
10
17
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3512kb

input:

4 1
0
1
10
17

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Runtime Error

input:

500 859
7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...

output:


result: