QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#347722 | #8340. 3 Sum | ucup-team087# | AC ✓ | 415ms | 21404kb | C++14 | 9.4kb | 2024-03-09 15:06:02 | 2024-10-13 18:47:51 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
// fast IO by yosupo
// sc.read(string &) appends the input
struct Scanner {
FILE* fp = nullptr;
char line[(1 << 15) + 1];
size_t st = 0, ed = 0;
void reread() {
memmove(line, line + st, ed - st);
ed -= st;
st = 0;
ed += fread(line + ed, 1, (1 << 15) - ed, fp);
line[ed] = '\0';
}
bool succ() {
while (true) {
if (st == ed) {
reread();
if (st == ed) return false;
}
while (st != ed && isspace(line[st])) st++;
if (st != ed) break;
}
if (ed - st <= 50) reread();
return true;
}
template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
bool read_single(T& ref) {
if (!succ()) return false;
while (true) {
size_t sz = 0;
while (st + sz < ed && !isspace(line[st + sz])) sz++;
ref.append(line + st, sz);
st += sz;
if (!sz || st != ed) break;
reread();
}
return true;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
bool read_single(T& ref) {
if (!succ()) return false;
bool neg = false;
if (line[st] == '-') {
neg = true;
st++;
}
ref = T(0);
while (isdigit(line[st])) {
ref = 10 * ref + (line[st++] - '0');
}
if (neg) ref = -ref;
return true;
}
template <class T> bool read_single(vector<T>& ref) {
for (auto& d : ref) {
if (!read_single(d)) return false;
}
return true;
}
void read() {}
template <class H, class... T> void read(H& h, T&... t) {
bool f = read_single(h);
assert(f);
read(t...);
}
Scanner(FILE* _fp) : fp(_fp) {}
};
struct Printer {
public:
template <bool F = false> void write() {}
template <bool F = false, class H, class... T>
void write(const H& h, const T&... t) {
if (F) write_single(' ');
write_single(h);
write<true>(t...);
}
template <class... T> void writeln(const T&... t) {
write(t...);
write_single('\n');
}
void flush() {
fwrite(line, 1, pos, fp);
pos = 0;
}
Printer(FILE* _fp) : fp(_fp) {}
~Printer() { flush(); }
private:
static constexpr size_t SIZE = 1 << 15;
FILE* fp;
char line[SIZE], small[50];
size_t pos = 0;
void write_single(const char& val) {
if (pos == SIZE) flush();
line[pos++] = val;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void write_single(T val) {
if (pos > (1 << 15) - 50) flush();
if (val == 0) {
write_single('0');
return;
}
if (val < 0) {
write_single('-');
val = -val; // todo min
}
size_t len = 0;
while (val) {
small[len++] = char('0' + (val % 10));
val /= 10;
}
for (size_t i = 0; i < len; i++) {
line[pos + i] = small[len - 1 - i];
}
pos += len;
}
void write_single(const string& s) {
for (char c : s) write_single(c);
}
void write_single(const char* s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) write_single(s[i]);
}
template <class T> void write_single(const vector<T>& val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write_single(' ');
write_single(val[i]);
}
}
void write_single(long double d){
{
long long v=d;
write_single(v);
d-=v;
}
write_single('.');
for(int _=0;_<8;_++){
d*=10;
long long v=d;
write_single(v);
d-=v;
}
}
};
Scanner sc(stdin);
Printer pr(stdout);
using U = unsigned long long;
constexpr int L = 6;
constexpr U MS[] =
{
// 1,2,3,4,5,6,7,8,9,10,
202400000000000113ULL, 202400000000000123ULL, 202400000000000203ULL, 202400000000000351ULL, 202400000000000447ULL, 202400000000000479ULL, 202400000000000501ULL, 202400000000000617ULL, 202400000000000639ULL, 202400000000000683ULL, 202400000000000707ULL, 202400000000000729ULL, 202400000000000783ULL, 202400000000000827ULL, 202400000000000849ULL, 202400000000000857ULL, 202400000000000861ULL, 202400000000000867ULL, 202400000000000911ULL, 202400000000000947ULL, 202400000000000983ULL, 202400000000001031ULL, 202400000000001101ULL, 202400000000001121ULL, 202400000000001217ULL, 202400000000001247ULL, 202400000000001253ULL, 202400000000001269ULL, 202400000000001337ULL, 202400000000001383ULL, 202400000000001407ULL, 202400000000001509ULL, 202400000000001563ULL, 202400000000001611ULL, 202400000000001619ULL, 202400000000001689ULL, 202400000000001691ULL, 202400000000001707ULL, 202400000000001737ULL, 202400000000001751ULL, 202400000000001799ULL, 202400000000001883ULL, 202400000000002031ULL, 202400000000002033ULL, 202400000000002121ULL, 202400000000002213ULL, 202400000000002283ULL, 202400000000002309ULL, 202400000000002313ULL, 202400000000002351ULL, 202400000000002381ULL, 202400000000002451ULL, 202400000000002471ULL, 202400000000002487ULL, 202400000000002501ULL, 202400000000002531ULL, 202400000000002613ULL, 202400000000002621ULL, 202400000000002669ULL, 202400000000002781ULL, 202400000000002801ULL, 202400000000002919ULL, 202400000000002927ULL, 202400000000002963ULL, 202400000000003009ULL, 202400000000003021ULL, 202400000000003041ULL, 202400000000003111ULL, 202400000000003149ULL, 202400000000003161ULL, 202400000000003207ULL, 202400000000003353ULL, 202400000000003389ULL, 202400000000003441ULL, 202400000000003479ULL, 202400000000003489ULL, 202400000000003497ULL, 202400000000003521ULL, 202400000000003593ULL, 202400000000003761ULL, 202400000000003777ULL, 202400000000003803ULL, 202400000000003831ULL, 202400000000003929ULL, 202400000000003969ULL, 202400000000003989ULL, 202400000000004007ULL, 202400000000004049ULL, 202400000000004073ULL, 202400000000004113ULL, 202400000000004143ULL, 202400000000004179ULL, 202400000000004223ULL, 202400000000004271ULL, 202400000000004349ULL, 202400000000004449ULL, 202400000000004557ULL, 202400000000004707ULL, 202400000000004713ULL, 202400000000004731ULL}
;
#define M MS[l]
int N, K;
U A[510][L];
int main() {
sc.read(N, K);
for (int i = 0; i < N; ++i) {
string S;
sc.read(S);
reverse(S.begin(), S.end());
const int SLen = S.size();
vector<Int> rs(K + 1, 0);
for (int x = 0; x < SLen; ++x) {
rs[x % K] += (S[x] - '0');
}
for (; ; ) {
for (int x = 0; x < K; ++x) {
rs[x + 1] += rs[x] / 10;
rs[x] %= 10;
}
if (rs[K] == 0) break;
rs[0] += rs[K];
rs[K] = 0;
}
{
bool all9 = true;
for (int x = 0; x < K; ++x) {
all9 = all9 && (rs[x] == 9);
}
if (all9) {
fill(rs.begin(), rs.end(), 0);
}
}
// cerr<<"rs = "<<rs<<endl;
for (int l = 0; l < L; ++l) {
A[i][l] = 0;
for (int x = K; --x >= 0; ) {
((A[i][l] *= 10) += rs[x]) %= M;
}
}
// pv(A[i],A[i]+L);
}
// 10^K-1
vector<U> tar(L, 0);
for (int l = 0; l < L; ++l) {
for (int x = 0; x < K; ++x) {
((tar[l] *= 10) += 9) %= M;
}
}
map<vector<U>, int> freq;
Int ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= i; ++j) {
vector<U> key(L, 0);
for (int l = 0; l < L; ++l) {
key[l] = A[i][l] + A[j][l];
if (key[l] >= M) key[l] -= M;
}
++freq[key];
}
for (int h = 0; h < 3; ++h) {
vector<U> key(L, 0);
for (int l = 0; l < L; ++l) {
key[l] = h * tar[l];
if (key[l] >= M) key[l] -= M;
key[l] -= A[i][l];
if (key[l] >= M) key[l] += M;
}
auto it = freq.find(key);
if (it != freq.end()) {
ans += it->second;
}
}
}
printf("%lld\n", ans);
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 76ms
memory: 21360kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 415ms
memory: 21404kb
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 56ms
memory: 4108kb
input:
500 1 751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...
output:
2327631
result:
ok 1 number(s): "2327631"
Test #5:
score: 0
Accepted
time: 54ms
memory: 3912kb
input:
500 2 408542968136435277974575411503179002415404345446801430469044749372949272333801248935236224652806667129749035002588943020176263162139056819871274824302889304493205266143688886696157147111754418731401856424401766968832165255416237731963027205324149660112574729610391396555581935236134531799950318...
output:
212002
result:
ok 1 number(s): "212002"
Test #6:
score: 0
Accepted
time: 270ms
memory: 4824kb
input:
500 11500 75411775796562109942642493394321873284995260953010112281856775261847503626737348402159485133662757032091519863427156582689971229143089317472838196453888261138079171290535429921921548971897026706656838415620603757605079012541561774699628665865662183868374645956694140356716037674688084770628...
output:
7675
result:
ok 1 number(s): "7675"
Test #7:
score: 0
Accepted
time: 284ms
memory: 10116kb
input:
500 11500 85355036663164764459816544518601485185320972076300982726542821424439713703229669576802138231401047471351087455159512255765325323540671792953715169122669767368905391325060775725733157611188832204902997772518104188947349204726490597030311894441123834099315122116302203972018409854605418988681...
output:
1070
result:
ok 1 number(s): "1070"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
1 11500 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
1
result:
ok 1 number(s): "1"
Extra Test:
score: 0
Extra Test Passed