QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722585 | #8340. 3 Sum | pmt2018# | AC ✓ | 117ms | 14948kb | C++17 | 5.1kb | 2024-11-07 19:37:07 | 2024-11-07 19:37:07 |
Judging History
answer
/*
Problem : M. 3 Sum
Url : https://qoj.ac/contest/1540/problem/8340
Date : 2024/11/7 18:55:03
Solver : pmt2018
*/
#include<bits/stdc++.h>
#include <bits/extc++.h>
#define y0 pmtx
#define y1 pmtxx
#define x0 pmtxxx
#define x1 pmtxxxx
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define DEBUG printf("Passing Line %d in function [%s].\n",__LINE__,__FUNCTION__)
using namespace std;
using namespace __gnu_pbds;
typedef pair<int ,int > pii;
typedef vector<int > vi;
typedef long long ll;
typedef unsigned long long ull;
namespace FastIO{
const int SIZE=(1<<20);
char in[SIZE],*inS=in,*inT=in+SIZE;
inline char Getchar(){
if(inS==inT){inT=(inS=in)+fread(in,1,SIZE,stdin);if(inS==inT)return EOF;}
return *inS++;
}
char out[SIZE],*outS=out,*outT=out+SIZE;
inline void Flush(){fwrite(out,1,outS-out,stdout);outS=out;}
inline void Putchar(char c){*outS++=c;if(outS==outT)Flush();}
struct NTR{~NTR(){Flush();}}ZTR;
}
#ifndef LOCAL
#define getchar FastIO::Getchar
#define putchar FastIO::Putchar
#endif
template<typename T> inline void read(T &x){
x=0;int f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
x*=f;
}
inline void readstr(char* str){
int len=0;char c=getchar();
while(c==' '||c=='\n')c=getchar();
while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();
str[len] = '\0';
}
template<typename T>inline void write(T x){
if(!x)putchar('0');
if(x<0)x=-x,putchar('-');
static int sta[20];int tot=0;
while(x)sta[tot++]=x%10,x/=10;
while(tot)putchar(sta[--tot]+48);
}
inline void writestr(char* str){int cur=0;while(str[cur])putchar(str[cur++]);}
const int maxn=200007,INF=0x3f3f3f3f;
const ll MOD=998244353;
const ll LINF=0x3f3f3f3f3f3f3f3fll;
const ll P=19260817;
template<typename T>inline void ckmax(T &x,T y){x=(y>x?y:x);}
template<typename T>inline void ckmin(T &x,T y){x=(y<x?y:x);}
template<typename T>inline T my_abs(T x){if(x<0)x=-x;return x;}
// inline int mod1(int x){return x<MOD?x:x-MOD;}
// inline int mod2(int x){return x<0?x+MOD:x;}
// inline void add(int &x,int y){x=mod1(x+y);}
// inline void sub(int &x,int y){x=mod2(x-y);}
int n, K;
pii h[maxn];
char s[maxn];
int num[maxn];
const int mod1 = 1e9 + 7, mod2 = 1e9 + 9;
// typedef uint64_t ull;
mt19937_64 rnd(time(nullptr));
const ull mask = rnd();
const ull base = rnd();
ull xorshift(ull x) {
x ^= mask;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
x ^= mask;
return x;
}
inline ull key(int ai, int bi) {
return xorshift(((1ull * ai) << 32) | (1ull * bi));
}
gp_hash_table <ull, int> vis;
pii solve(){
int l = strlen(s + 1);
// cout<<l<<endl;
if(l==1&&s[1] == '0')return mp(0,0);
for(int i = l; i >= 1; i--) {
num[l-i]=s[i]-'0';
}
while(true) {
for(int i = K; i < l; i++) {
num[i%K] += num[i];
num[i] = 0;
}
for(int i = 0; i < K; i++) {
num[i + 1] += num[i] / 10;
num[i] %= 10;
}
for(l = K; num[l] != 0; l ++){
num[l + 1] += num[l] / 10;
num[l] %= 10;
}
// cout<<l<<endl;
if(l <= K) break;
}
bool all9 = 1;
for(int i = 0; i < K; i++){
if(num[i]!=9)all9=0;
}
if(all9)for(int i=0;i<K;i++)num[i]=0;
// int pw1 = 1, pw2 = 1;
int ans1 = 0, ans2 = 0;
for(int i = K - 1; i >= 0; i--) {
ans1 = (10ll * ans1 % mod1 + num[i]) % mod1;
ans2 = (10ll * ans2 % mod2 + num[i]) % mod2;
}
for(int i = 0; i < l; i++)num[i] = 0;
// cout<<ans1<<' '<<ans2<<endl;
return mp(ans1, ans2);
}
int main(){
#ifdef LOCAL
// freopen(".in","r",stdin);
// freopen(".in","w",stdout);
#else
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
#endif
scanf("%d%d", &n, &K);
for(int i=1;i<=n;i++){
// readstr(s + 1);
scanf("%s", s + 1);
h[i] = solve();
}
pii M, M2;
M.fi = M.se = 1;
for(int i = 1; i <= K; i++) {
M.fi = 10ll * M.fi % mod1;
M.se = 10ll * M.se % mod2;
}
M.fi = (M.fi - 1ll + mod1) % mod1;
M.se = (M.se - 1ll + mod2) % mod2;
// cout<<M.fi<<' '<<M.se<<endl;
M2 = mp((M.fi + M.fi) % mod1, (M.se + M.se) % mod2);
// cout<<M2.fi<<' '<<M2.se<<endl;
int ans = 0;
for(int i = 1; i <= n; i++) {
vis[key((- h[i].fi + mod1) % mod1, (- h[i].se + mod2) % mod2)] ++;
vis[key((M2.fi - h[i].fi + mod1) % mod1, (M2.se - h[i].se + mod2) % mod2)] ++;
vis[key((M.fi - h[i].fi + mod1) % mod1, (M.se - h[i].se + mod2) % mod2)] ++;
for(int j = i; j <= n; j++) {
pii cur = mp((h[i].fi + h[j].fi) % mod1, (h[i].se + h[j].se) % mod2);
ans += vis[key(cur.fi,cur.se)];
}
}
printf("%d", ans);
return 0;
}
//things to remember
//1.long long
//2.array length
//3.freopen
//4 boarder case
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5900kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 6ms
memory: 14644kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 117ms
memory: 14948kb
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 37ms
memory: 8020kb
input:
500 1 751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...
output:
2327631
result:
ok 1 number(s): "2327631"
Test #5:
score: 0
Accepted
time: 36ms
memory: 6048kb
input:
500 2 408542968136435277974575411503179002415404345446801430469044749372949272333801248935236224652806667129749035002588943020176263162139056819871274824302889304493205266143688886696157147111754418731401856424401766968832165255416237731963027205324149660112574729610391396555581935236134531799950318...
output:
212002
result:
ok 1 number(s): "212002"
Test #6:
score: 0
Accepted
time: 90ms
memory: 6164kb
input:
500 11500 75411775796562109942642493394321873284995260953010112281856775261847503626737348402159485133662757032091519863427156582689971229143089317472838196453888261138079171290535429921921548971897026706656838415620603757605079012541561774699628665865662183868374645956694140356716037674688084770628...
output:
7675
result:
ok 1 number(s): "7675"
Test #7:
score: 0
Accepted
time: 90ms
memory: 10264kb
input:
500 11500 85355036663164764459816544518601485185320972076300982726542821424439713703229669576802138231401047471351087455159512255765325323540671792953715169122669767368905391325060775725733157611188832204902997772518104188947349204726490597030311894441123834099315122116302203972018409854605418988681...
output:
1070
result:
ok 1 number(s): "1070"
Test #8:
score: 0
Accepted
time: 1ms
memory: 8008kb
input:
1 11500 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
1
result:
ok 1 number(s): "1"
Extra Test:
score: 0
Extra Test Passed