# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884917 |
2023-12-08T16:46:42 Z |
devvops |
Lottery (CEOI18_lot) |
C++17 |
|
265 ms |
65536 KB |
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <climits>
#include <random>
using namespace std;
#define ll long long
#define pb push_back
#define ull unsigned long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
const int mod = (int) 1e9 + 7;
const int P = 337;
int a[10001];
int n, l, q;
void sub3(){
ll hsh[n + 1];
ll p[l + 1];
p[0] = 1;
for(int i = 1; i <= l; i++){
p[i] = (p[i - 1] * (P + 0LL)) % mod;
}
for(int i = 1; i <= n; i++){
hsh[i] = (hsh[i - 1] * (P + 0LL)) % mod;
hsh[i] += a[i];
if(hsh[i] >= mod) hsh[i] -= mod;
}
for(int l1 = 1; l1 <= n - l + 1; l1++){
int r1 = l1 + l - 1;
ll g1 = (hsh[l1 - 1] * p[r1 - l1 + 1]) % mod;
g1 = hsh[r1] - g1;
if(g1 < 0) g1 += mod;
int ans = 0;
for(int l2 = 1; l2 <= n - l + 1; l2++){
if(l1 == l2) continue;
int r2 = l2 + l - 1;
ll g2 = (hsh[l2 - 1] * p[r2 - l2 + 1]) % mod;
g2 = hsh[r2] - g2;
if(g2 < 0) g2 += mod;
if(g1 == g2) ans++;
}
cout << ans << " ";
}
}
void sub2(){
int pref[n + 1][n + 1];
int dp[n + 1][n + 1];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
pref[i][j] = 0;
dp[i][j] = 0;
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
pref[i][j] = pref[i - 1][j - 1] + (a[i] == a[j]);
}
}
for(int l1 = 1; l1 <= n - l + 1; l1++){
int r1 = l1 + l - 1;
for(int l2 = 1; l2 <= n - l + 1; l2++){
int r2 = l2 + l - 1;
int k = (r1 - l1 + 1) - (pref[r1][r2] - pref[l1 - 1][l2 - 1]);
dp[l1][k]++;
}
}
for(int i = 1; i <= n; i++){
int p = 0;
for(int j = 0; j <= l; j++){
dp[i][j] += p;
p = dp[i][j];
}
}
while(q--){
int k;
cin >> k;
for(int i = 1; i <= n - l + 1; i++){
cout << dp[i][k] - 1 << " ";
}
cout << '\n';
}
}
void sub2_1(int k){
int pref[n + 1][n + 1];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
pref[i][j] = 0;
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
pref[i][j] = pref[i - 1][j - 1] + (a[i] == a[j]);
}
}
for(int l1 = 1; l1 <= n - l + 1; l1++){
int r1 = l1 + l - 1;
int cnt = 0, p = 0;
for(int l2 = 1; l2 <= n - l + 1; l2++){
if(l1 == l2) continue;
int r2 = l2 + l - 1;
int x = (r1 - l1 + 1) - (pref[r1][r2] - pref[l1 - 1][l2 - 1]);
if(x <= k){
cnt++;
}
}
cout << cnt << " ";
}
}
void solve(){
cin >> n >> l;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
cin >> q;
if(q == 1 && n > 2000){
int k;
cin >> k;
if(k == 0){
sub3();
}
else{
sub2_1(k);
}
}
else{
sub2();
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int xach = 1;
//cin >> xach;
while(xach--) solve();
}
/*
*
*/
Compilation message
lot.cpp: In function 'void sub2_1(int)':
lot.cpp:130:22: warning: unused variable 'p' [-Wunused-variable]
130 | int cnt = 0, p = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
26 ms |
31828 KB |
Output is correct |
14 |
Correct |
27 ms |
31860 KB |
Output is correct |
15 |
Correct |
26 ms |
31824 KB |
Output is correct |
16 |
Correct |
29 ms |
31824 KB |
Output is correct |
17 |
Correct |
29 ms |
31836 KB |
Output is correct |
18 |
Correct |
28 ms |
31824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
828 KB |
Output is correct |
2 |
Correct |
262 ms |
572 KB |
Output is correct |
3 |
Correct |
264 ms |
592 KB |
Output is correct |
4 |
Correct |
258 ms |
924 KB |
Output is correct |
5 |
Correct |
70 ms |
604 KB |
Output is correct |
6 |
Correct |
228 ms |
604 KB |
Output is correct |
7 |
Correct |
67 ms |
604 KB |
Output is correct |
8 |
Correct |
130 ms |
956 KB |
Output is correct |
9 |
Correct |
250 ms |
656 KB |
Output is correct |
10 |
Correct |
254 ms |
848 KB |
Output is correct |
11 |
Correct |
11 ms |
344 KB |
Output is correct |
12 |
Correct |
130 ms |
604 KB |
Output is correct |
13 |
Correct |
93 ms |
604 KB |
Output is correct |
14 |
Correct |
93 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
828 KB |
Output is correct |
2 |
Correct |
262 ms |
572 KB |
Output is correct |
3 |
Correct |
264 ms |
592 KB |
Output is correct |
4 |
Correct |
258 ms |
924 KB |
Output is correct |
5 |
Correct |
70 ms |
604 KB |
Output is correct |
6 |
Correct |
228 ms |
604 KB |
Output is correct |
7 |
Correct |
67 ms |
604 KB |
Output is correct |
8 |
Correct |
130 ms |
956 KB |
Output is correct |
9 |
Correct |
250 ms |
656 KB |
Output is correct |
10 |
Correct |
254 ms |
848 KB |
Output is correct |
11 |
Correct |
11 ms |
344 KB |
Output is correct |
12 |
Correct |
130 ms |
604 KB |
Output is correct |
13 |
Correct |
93 ms |
604 KB |
Output is correct |
14 |
Correct |
93 ms |
600 KB |
Output is correct |
15 |
Runtime error |
37 ms |
65536 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
26 ms |
31828 KB |
Output is correct |
14 |
Correct |
27 ms |
31860 KB |
Output is correct |
15 |
Correct |
26 ms |
31824 KB |
Output is correct |
16 |
Correct |
29 ms |
31824 KB |
Output is correct |
17 |
Correct |
29 ms |
31836 KB |
Output is correct |
18 |
Correct |
28 ms |
31824 KB |
Output is correct |
19 |
Correct |
265 ms |
828 KB |
Output is correct |
20 |
Correct |
262 ms |
572 KB |
Output is correct |
21 |
Correct |
264 ms |
592 KB |
Output is correct |
22 |
Correct |
258 ms |
924 KB |
Output is correct |
23 |
Correct |
70 ms |
604 KB |
Output is correct |
24 |
Correct |
228 ms |
604 KB |
Output is correct |
25 |
Correct |
67 ms |
604 KB |
Output is correct |
26 |
Correct |
130 ms |
956 KB |
Output is correct |
27 |
Correct |
250 ms |
656 KB |
Output is correct |
28 |
Correct |
254 ms |
848 KB |
Output is correct |
29 |
Correct |
11 ms |
344 KB |
Output is correct |
30 |
Correct |
130 ms |
604 KB |
Output is correct |
31 |
Correct |
93 ms |
604 KB |
Output is correct |
32 |
Correct |
93 ms |
600 KB |
Output is correct |
33 |
Runtime error |
37 ms |
65536 KB |
Execution killed with signal 9 |
34 |
Halted |
0 ms |
0 KB |
- |