QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625361 | #8340. 3 Sum | xiangji# | TL | 4ms | 84892kb | C++17 | 2.4kb | 2024-10-09 18:53:15 | 2024-10-09 18:53:16 |
Judging History
answer
// #pragma GCC optimize(2)
// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "D:/OneDrive/study/cpp/.vscode/debug.h"
#else
#define debug(...) 42;
#endif
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ll __int128_t
mt19937 rd(chrono::system_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2e5 + 10;
const double eps = 1e-6;
int n, k;
vector<vector<int>> ans(510, vector<int>(20010));
bool check(int a, int b, int c)
{
vector<int> sum(k);
// for (int i = 0; i < k; ++i)
// {
// cout << ans[a][i];
// }
// cout << endl;
// for (int i = 0; i < k; ++i)
// {
// cout << ans[b][i];
// }
// cout << endl;
// for (int i = 0; i < k; ++i)
// {
// cout << ans[c][i];
// }
// cout << endl
// << endl;
for (int i = 0; i < k; ++i)
{
sum[i] += ans[a][i] + ans[b][i] + ans[c][i];
sum[(i + 1) % k] += sum[i] / 10;
sum[i] %= 10;
}
for (int i = 0; i < k; ++i)
{
sum[(i + 1) % k] += sum[i] / 10;
sum[i] %= 10;
}
int p = sum[0];
if (p != 0 && p != 9)
return false;
for (int i = 0; i < k; ++i)
{
if (sum[i] != p)
return false;
}
return true;
}
void solve()
{
cin >> n >> k;
vector<string> a(n + 1);
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
int len = a[i].length();
int cnt = 0;
for (int j = len - 1; j >= 0; --j)
{
ans[i][cnt] += a[i][j] - '0';
ans[i][(cnt + 1) % k] += ans[i][cnt] / 10;
ans[i][(cnt + 1) % k] = ans[i][cnt] % 10;
}
for (int j = 0; j < k; ++j)
{
ans[i][(j + 1) % k] += ans[i][j] / 10;
ans[i][j] %= 10;
}
}
int ans = 0;
for (int i = 1; i <= n; ++i)
{
for (int j = i; j <= n; ++j)
{
for (int k = j; k <= n; ++k)
{
if (check(i, j, k))
{
ans++;
}
}
}
}
cout << ans;
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin>>_;
while (_--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 84892kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Time Limit Exceeded
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...