QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#349874 | #8340. 3 Sum | ucup-team992# | ML | 0ms | 0kb | C++20 | 3.6kb | 2024-03-10 06:57:55 | 2024-03-10 06:57:56 |
Judging History
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[500];
uci cnum[500];
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: 0
Memory Limit Exceeded
input:
4 1 0 1 10 17
output:
3