QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#709175 | #8340. 3 Sum | _LSA_ | WA | 280ms | 83760kb | C++14 | 4.3kb | 2024-11-04 12:32:31 | 2024-11-04 12:32:32 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
using namespace std;
ll read(){
ll X = 0 ,r = 1;
char ch = getchar();
while(!isdigit(ch) && ch != '-') ch = getchar();
if(ch == '-') r = -1,ch = getchar();
while(isdigit(ch)) X = X*10+ch-'0',ch = getchar();
return X*r;
}
const int N = 510;
const int M = 2e4+10;
int n,k;
struct BigNum{
int num[M],len;
void init(){
string s;
cin >> s;
len = s.size();
for(int i=0;i<len;i++) num[len-i] = s[i]-'0';
// cout << "111\n";
// for(int i=1;i<=len;i++) cout << num[i];
// cout << "\n";
while(len > k){
for(int i=k;i<=len;i+=k)
for(int j=1;j<=k&&i+j<=len;i++){
num[j] += num[i+j];
num[i+j] = 0;
}
len = k;
for(int i=1;i<=len;i++){
if(num[i] >= 10){
num[i+1] += num[i]/10;
num[i] %= 10;
if(i == len) len++;
}
}
}
// for(int i=1;i<=k;i++) cout << num[i];
// cout << "\n";
for(int i=1;i<=k;i++)
if(num[i] != 9) return ;
for(int i=1;i<=k;i++) num[i] = 0;
len = 1;
}
ll get(int mod){
ll res = 0;
for(int i=1;i<=len;i++) res = (res*10+num[i])%mod;
return res;
}
}a[N],c[2];
const int mod1 = 998244353,mod2 = 1e9+7,mod3 = 1e9+9;
struct modint{
long long x1,x2,x3;
modint operator+(const int &x)const{
modint res = {x1,x2,x3};
res.x1 = res.x1+x < mod1 ? res.x1+x : res.x1+x-mod1;
res.x2 = res.x2+x < mod2 ? res.x2+x : res.x2+x-mod2;
res.x3 = res.x3+x < mod3 ? res.x3+x : res.x3+x-mod3;
return res;
}
modint operator-(const int &x)const{
modint res = {x1,x2,x3};
res.x1 = res.x1-x > 0 ? res.x1-x : res.x1-x+mod1;
res.x2 = res.x2-x > 0 ? res.x2-x : res.x2-x+mod2;
res.x3 = res.x3-x > 0 ? res.x3-x : res.x3-x+mod3;
return res;
}
modint operator*(const int &x)const{
modint res = {x1,x2,x3};
res.x1 = res.x1*x%mod1;
res.x2 = res.x2*x%mod2;
res.x3 = res.x3*x%mod3;
return res;
}
modint operator+(const modint &x)const{
modint res = {x1,x2,x3};
res.x1 = res.x1+x.x1 < mod1 ? res.x1+x.x1 : res.x1+x.x1-mod1;
res.x2 = res.x2+x.x2 < mod2 ? res.x2+x.x2 : res.x2+x.x2-mod2;
res.x3 = res.x3+x.x3 < mod3 ? res.x3+x.x3 : res.x3+x.x3-mod3;
return res;
}
modint operator-(const modint &x)const{
modint res = {x1,x2,x3};
res.x1 = res.x1-x.x1 > 0 ? res.x1-x.x1 : res.x1-x.x1+mod1;
res.x2 = res.x2-x.x2 > 0 ? res.x2-x.x2 : res.x2-x.x2+mod2;
res.x3 = res.x3-x.x3 > 0 ? res.x3-x.x3 : res.x3-x.x3+mod3;
return res;
}
modint operator*(const modint &x)const{
modint res = {x1,x2,x3};
res.x1 = res.x1*x.x1%mod1;
res.x2 = res.x2*x.x2%mod2;
res.x3 = res.x3*x.x3%mod3;
return res;
}
bool operator<(const modint x)const{
if(x1 != x.x1) return x1 < x.x1;
if(x2 != x.x2) return x2 < x.x2;
return x3 < x.x3;
}
bool operator == (const modint x)const{
return x1 == x.x1 && x2 == x.x2 && x3 == x.x3;
}
bool operator != (const modint x)const{
return x1 != x.x1 || x2 != x.x2 || x3 != x.x3;
}
}b[N],d[2];
signed main(){
n = read(); k = read();
for(int i=1;i<=n;i++) a[i].init();
c[0].len = k;
for(int i=1;i<=k;i++) c[0].num[i] = 9;
c[1].len = k+1;
c[1].num[1] = 1;
for(int i=2;i<=k;i++) c[1].num[i] = 9;
c[1].num[k+1] = 8;
for(int i=1;i<=n;i++)
b[i] = modint{a[i].get(mod1),a[i].get(mod2),a[i].get(mod3)};
d[0] = modint{c[0].get(mod1),c[0].get(mod2),c[0].get(mod3)};
d[1] = modint{c[1].get(mod1),c[1].get(mod2),c[1].get(mod3)};
int ans = 0;
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
for(int k=j;k<=n;k++) ans += (b[i]+b[j]+b[k] == modint{0,0,0}) || (b[i]+b[j]+b[k] == d[0]) || (b[i]+b[j]+b[k] == d[1]);
cout << ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5676kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 62ms
memory: 81640kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 280ms
memory: 83072kb
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 234ms
memory: 83760kb
input:
500 1 751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...
output:
2327631
result:
ok 1 number(s): "2327631"
Test #5:
score: -100
Wrong Answer
time: 190ms
memory: 81860kb
input:
500 2 408542968136435277974575411503179002415404345446801430469044749372949272333801248935236224652806667129749035002588943020176263162139056819871274824302889304493205266143688886696157147111754418731401856424401766968832165255416237731963027205324149660112574729610391396555581935236134531799950318...
output:
211321
result:
wrong answer 1st numbers differ - expected: '212002', found: '211321'