QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534031 | #8340. 3 Sum | training_233# | WA | 0ms | 9584kb | C++14 | 3.0kb | 2024-08-26 19:34:38 | 2024-08-26 19:34:39 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
using namespace std;
const long long mod=1e18;
int n,m,ans,cnt;
long long base;
string s;
struct num
{
int len;
long long a[1501];
num()
{
len=0;
memset(a,0,sizeof a);
}
inline void init(string s)
{
reverse(s.begin(),s.end());
while(s.length()%18)
s.push_back('0');
len=s.length()/18;
for(int i=len;i>=1;--i)
for(int j=1;j<=18;++j)
{
a[i]=a[i]*10+s.back()-'0';
s.pop_back();
}
}
bool operator <(const num &other) const
{
if(len^other.len)
return len<other.len;
for(int i=len;i>=1;--i)
if(a[i]^other.a[i])
return a[i]<other.a[i];
return 1;
}
bool operator ==(const num &other) const
{
if(len^other.len)
return 0;
for(int i=len;i>=1;--i)
if(a[i]^other.a[i])
return 0;
return 1;
}
}a[501],tmp,M;
map<num,int> mp;
inline num operator +(const num &x,const num &y)
{
num res;
res.len=max(x.len,y.len);
long long d=0;
for(int i=1;i<=res.len;++i)
{
res.a[i]=x.a[i]+y.a[i]+d;
d=res.a[i]/mod;
res.a[i]%=mod;
}
while(d)
{
res.a[++res.len]=d;
d=res.a[res.len]/mod;
res.a[res.len]%=mod;
}
return res;
}
inline num operator -(const num &x,const num &y)
{
num res;
res.len=x.len;
long long d=0;
for(int i=1;i<=res.len;++i)
{
res.a[i]=x.a[i]-y.a[i]-d;
d=0;
if(res.a[i]<0)
{
res.a[i]+=mod;
d=mod;
}
}
while(!res.a[res.len])
--res.len;
return res;
}
inline num solve(num x)
{
while(!(x<M))
{
tmp.len=M.len;
for(int i=1;i<tmp.len;++i)
tmp.a[i]=x.a[i];
tmp.a[tmp.len]=x.a[tmp.len]%base;
for(int i=tmp.len;i<=x.len;++i)
x.a[i-tmp.len+1]=x.a[i]/base+x.a[i+1]%base*(mod/base);
x.len-=tmp.len-1;
while(!x.a[x.len])
--x.len;
for(int i=1;i<=tmp.len;++i)
tmp.a[i]=x.a[i+m];
x.len=m;
x=tmp+x;
}
return x;
}
inline void init()
{
ios::sync_with_stdio(0);
cin.tie(0);
}
int main()
{
init();
cin>>n>>m;
cnt=m%18;
base=1;
for(int i=1;i<=cnt;++i)
base*=10;
for(int i=1;i<=m;++i)
s.push_back('9');
M.init(s);
for(int i=1;i<=n;++i)
{
cin>>s;
a[i].init(s);
a[i]=solve(a[i]);
}
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
ans+=!solve(a[i]+a[i]+a[j]).len;
for(int i=1;i<=n;++i)
{
num val=M-a[i];
for(int j=i+1;j<=n;++j)
ans+=mp[val+a[j]];
++mp[a[i]];
}
cout<<ans<<'\n';
cout.flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 9584kb
input:
4 1 0 1 10 17
output:
4
result:
wrong answer 1st numbers differ - expected: '3', found: '4'