QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#349875#8340. 3 Sumucup-team992#TL 55ms468984kbC++203.6kb2024-03-10 06:58:172024-03-10 06:58:18

Judging History

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

  • [2024-09-20 10:20:30]
  • hack成功,自动添加数据
  • (/hack/848)
  • [2024-03-18 21:48:05]
  • hack成功,自动添加数据
  • (/hack/579)
  • [2024-03-18 21:45:33]
  • hack成功,自动添加数据
  • (/hack/578)
  • [2024-03-10 06:58:18]
  • 评测
  • 测评结果:TL
  • 用时:55ms
  • 内存:468984kb
  • [2024-03-10 06:58:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define F first
#define S second
#define ar array
#define ll long long
typedef int uci;
#define int long long
struct node{
    int c{};
    uci ne[100];
    uci cnum[100];
    uci n;
};

node trie[580000];
int block[500][1160];
int val[20050];
int keyblock;
int keyceil;
int keyval;

int tn = 1;
int blockval;

void add(int b, int ind, int tr){
    trie[tr].c++;
    if(ind > keyblock){
        return;
    }
    for(int i{}; i < trie[tr].n; ++i){
        if(trie[tr].ne[i] == block[b][ind]){
            add(b, ind+1, trie[tr].cnum[i]);
            return;
        }
    }
    trie[tr].ne[trie[tr].n] = block[b][ind];
    trie[tr].cnum[trie[tr].n] = (tn++);
    trie[tr].n++;

    add(b, ind+1, tn-1);
}

int find(int ind, int tr){
    if(ind > keyblock){
        return trie[tr].c;
    }
    if(ind == keyblock){
        for(int i{}; i < trie[tr].n; ++i){
            if(trie[tr].ne[i] + val[ind] == keyval-1){
                return find(ind+1, trie[tr].cnum[i]);
            }
        }
    }else{
        for(int i{}; i < trie[tr].n; ++i){
            if(trie[tr].ne[i] + val[ind] == blockval){
                return find(ind+1, trie[tr].cnum[i]);
            }
        }
    }
    return 0;
}

void solve(){
    int n, k;
    cin >> n >> k;
    keyblock = (k-1)/18;
    keyceil = k%18;
    if(keyceil == 0)
        keyceil = 18;
    keyval = 1;
    for(int i{}; i < keyceil; ++i)
        keyval *= 10;
    blockval = 1;
    for(int i{}; i < 18; ++i)
        blockval *= 10;
    blockval--;


    for(int i{}; i < n; ++i){
        string s;
        cin >> s;

        for(int i{}; i < k; ++i){
            val[i] = 0;
        }
        for(int i{};i < s.size(); ++i){
            val[i%k] += s[i]-'0';
        }

        for(int i{}; i < k-1; ++i){
            val[i+1] += val[i]/10;
            val[i] = val[i]%10;
        }

        while(val[k-1] >= 10){
            int carry = val[k-1]/10;
            val[k-1] %= 10;

            val[0] += carry;
            for(int i{}; i < k-1; ++i){
                if(val[i] < 10)
                    break;
                val[i+1] += val[i]/10;
                val[i] %= 10;
            }
        }

        int bnum = 0;
        for(int j{}; j < k; j += 18){
            int mult = 1;
            for(int o = j; o < min(j+18, k); ++o){
                block[i][bnum] += mult*val[o];
                mult *= 10;
            }
            bnum++;
        }
    }

    int out{};
    for(int i{}; i < n; ++i){
        add(i, 0, 0);
        for(int j = i; j < n; ++j){
            int carry = 1;
            for(int k{}; k < keyblock; ++k){
                val[k] = block[i][k] + block[j][k] + carry;
                if(val[k] >= 1e18){
                    val[k] -= 1e18;
                    carry = 1;
                }else
                    carry = 0;
            }
            val[keyblock] = block[i][keyblock] + block[j][keyblock] + carry;
            if(val[keyblock] >= keyval){
                val[keyblock] -= keyval;
                carry = 1;
                if(keyblock == 0)
                    val[keyblock]++;
                for(int k{}; k < keyblock; ++k){
                    val[k]++;
                    if(val[k] >= 1e18){
                        val[k] -= 1e18;
                        carry = 1;
                    }else
                        break;
                }
            }

            int c = find(0, 0);
            out += c;
        }
    }
    cout << out << '\n';
}

uci main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 466520kb

input:

4 1
0
1
10
17

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 55ms
memory: 468984kb

input:

500 859
7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Time Limit Exceeded

input:

500 17336
11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...

output:


result: