QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#349444 | #8340. 3 Sum | ucup-team1516# | WA | 270ms | 15260kb | C++20 | 3.0kb | 2024-03-10 01:59:23 | 2024-03-10 01:59:25 |
Judging History
answer
#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
constexpr int mod = 998244853;
void mpl(int &x,int y) {
x += y;
if(x >= mod) x -= mod;
}
int calc(string s) {
int ans = 0;
for(int i = 0; i < s.size(); i++) {
ans = (10ll*ans+s[i]-'0')%mod;
}
return ans;
}
string plu(string s,string t) {
string ans = "";
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
int now = 0;
for(int i = 0; i < max(s.size(),t.size()); i++) {
int a = 0;
if(i < s.size()) a += s[i]-'0';
if(i < t.size()) a += t[i]-'0';
a += now;
ans += (char)('0'+a%10);
a /= 10;
now = a;
}
while(now) {
ans += (char)('0'+now%10);
now /= 10;
}
reverse(ans.begin(),ans.end());
return ans;
}
int calc2(string s,int K) {
vector<int>sum(s.size()+1);
for(int i = 0; i < s.size(); i++) {
sum[i+1] = (10ll*sum[i]+s[i]-'0')%mod;
}
int ans = 0;
for(int i = K; i < s.size(); i += K) {
mpl(ans,sum[s.size()-i]);
}
reverse(s.begin(),s.end());
string res = "0";
for(int i = 0; i < s.size(); i += K) {
string t = s.substr(i,min((int)(s.size()-i),K));
reverse(t.begin(),t.end());
res = plu(res,t);
}
if(res.size() > K) {
mpl(ans,calc2(res,K));
}
else if(res.size() == K && res == string(K,'9')) {
ans++;
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,K;
cin >> n >> K;
vector<string>s(n);
for(int i = 0; i < n; i++) {
cin >> s[i];
}
int M = calc(string(K,'9'));
vector<int>a(n);
for(int i = 0; i < n; i++) {
a[i] = calc(s[i]);
}
vector<int>b(n);
for(int i = 0; i < n; i++) {
b[i] = calc2(s[i],K);
}
int ans = 0;
for(int i = 0; i < n; i++) {
for(int j = i; j < n; j++) {
for(int k = j; k < n; k++) {
int now = ((long long)(a[i])+a[j]+a[k])%mod;
int now2 = 0;
mpl(now2,b[i]);
mpl(now2,b[j]);
mpl(now2,b[k]);
for(int l = 0; l <= 3; l++) {
if(1ll*now2*M%mod == now) {
ans++;
break;
}
mpl(now2,1);
}
}
}
}
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3476kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 124ms
memory: 4036kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 270ms
memory: 15260kb
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'