提出 #8612198
ソースコード 拡げる
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int N, K; cin >> N >> K;
map<int, ll> cnts;
ll ans = 0;
cnts.insert({0, 1});
ll pre = 0;
ll prefs[N+1]; prefs[0] = 0;
F0R(i, N) {
int A; cin >> A; A--;
pre += A; pre %= K;
prefs[i+1] = pre;
if (i >= K-1) {
cnts[prefs[i-K+1]]--;
}
if (cnts.count(pre)) {
ans += cnts[pre]; cnts[pre]++;
} else {
cnts.insert({pre, 1});
}
}
cout << ans << endl;
return 0;
}
// read the question correctly (ll vs int)
// template by bqi343
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Rem of Sum is Num |
| ユーザ | Geothermal |
| 言語 | C++14 (GCC 5.4.1) |
| 得点 | 500 |
| コード長 | 1873 Byte |
| 結果 | AC |
| 実行時間 | 151 ms |
| メモリ | 14336 KiB |
ジャッジ結果
| セット名 | sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| sample | sample01, sample02, sample03 |
| All | few01, few02, few03, hand01, hand02, hand03, hand04, large01, large02, large03, max01, max02, max03, mid01, mid02, mid03, mid04, mid05, min01, min02, min03, sample01, sample02, sample03, small01, small02, small03, small04, small05 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| few01 | AC | 16 ms | 1792 KiB |
| few02 | AC | 22 ms | 1792 KiB |
| few03 | AC | 23 ms | 1792 KiB |
| hand01 | AC | 1 ms | 256 KiB |
| hand02 | AC | 25 ms | 1792 KiB |
| hand03 | AC | 28 ms | 1792 KiB |
| hand04 | AC | 24 ms | 1792 KiB |
| large01 | AC | 104 ms | 13056 KiB |
| large02 | AC | 121 ms | 14336 KiB |
| large03 | AC | 110 ms | 13824 KiB |
| max01 | AC | 74 ms | 14336 KiB |
| max02 | AC | 82 ms | 14336 KiB |
| max03 | AC | 151 ms | 14336 KiB |
| mid01 | AC | 2 ms | 256 KiB |
| mid02 | AC | 2 ms | 384 KiB |
| mid03 | AC | 2 ms | 256 KiB |
| mid04 | AC | 2 ms | 384 KiB |
| mid05 | AC | 2 ms | 256 KiB |
| min01 | AC | 38 ms | 1408 KiB |
| min02 | AC | 36 ms | 1408 KiB |
| min03 | AC | 40 ms | 1408 KiB |
| sample01 | AC | 1 ms | 256 KiB |
| sample02 | AC | 1 ms | 256 KiB |
| sample03 | AC | 1 ms | 256 KiB |
| small01 | AC | 1 ms | 256 KiB |
| small02 | AC | 1 ms | 256 KiB |
| small03 | AC | 1 ms | 256 KiB |
| small04 | AC | 1 ms | 256 KiB |
| small05 | AC | 1 ms | 256 KiB |