QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#349865 | #8340. 3 Sum | ucup-team992# | TL | 44ms | 8532kb | C++20 | 3.5kb | 2024-03-10 06:53:47 | 2024-03-10 06:53:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ar array
#define ll long long
typedef int uci;
#define int long long
struct node{
int c{};
vector<int> ne;
vector<int> cnum;
};
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].ne.size(); ++i){
if(trie[tr].ne[i] == block[b][ind]){
add(b, ind+1, trie[tr].cnum[i]);
return;
}
}
trie[tr].ne.push_back(block[b][ind]);
trie[tr].cnum.push_back(tn++);
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].ne.size(); ++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].ne.size(); ++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: 2ms
memory: 5824kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 44ms
memory: 8532kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Time Limit Exceeded
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...