QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#773222 | #2507. 方差 | Link_Cut_Y | 76 | 978ms | 6260kb | C++14 | 3.3kb | 2024-11-23 06:22:57 | 2024-11-23 06:22:57 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <ctime>
#include <set>
#include <map>
#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i ++ )
#define rop(i, a, b) for (int i = (a); i < (b); i ++ )
#define dep(i, a, b) for (int i = (a); i >= (b); i -- )
#define dop(i, a, b) for (int i = (a); i > (b); i -- )
#define Darr(a, L, R) cerr << #a "[" << L << " ~ " << R << "] = "; rep(x, L, R) cerr << a[x] << " "; cerr << '\n';
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define D(x) (cerr << #x << " = " << x << '\n')
#define vit vector<int>::iterator
#define all(x) x.begin(), x.end()
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define chkmin(a, b) (a = min(a, b))
#define chkmax(a, b) (a = max(a, b))
#define sit set<int>::iterator
#define lowbit(x) (x & -x)
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pi acos(-1)
#define gc getchar
#define pc putchar
#define db double
#define y second
#define x first
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<db, db> PDD;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int mod = 998244353;
const int eps = 1e-9;
const int N = 1000010; int T = 1;
void print(int x) { dep(i, 20, 0) pc(((x >> i) & 1) ? '1' : '0'); }
int qpow(int a, int b = mod - 2, int s = 1) { for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) s = 1ll * s * a % mod; return s; }
namespace IO {
void read() { return; }
void write(char ch) { pc(ch); return; }
void write() { return; }
template <typename T> void read(T &x) { x = 0; T w = 0; char ch = gc(); while (ch < '0' || ch > '9') w |= (ch == '-'), ch = gc(); while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = gc(); x = w ? -x : x; }
template <typename T> void print(T x) { if (!x) return; print<T>(x / 10), pc((x % 10) ^ '0'); }
template <typename T> void write(T x) { if (x > 0) print<T>(x); else if (x < 0) pc('-'), print<T>(-x); else pc('0'); }
template <typename T> void write(T x, char en) { write<T>(x), pc(en); }
template <typename T, typename ...T2> void read(T &s, T2 &...oth) { read(s); read(oth...); return; }
}; using namespace IO;
const int INF = 1e15;
int ans = INF, n, a[N], b[N], c[N];
int calc() {
int s1 = 0, s2 = 0;
rep(i, 1, n) a[i] = a[i - 1] + c[i], s1 += a[i], s2 += a[i] * a[i];
int s = s2 * n - s1 * s1; ans = min(ans, s); return s;
}
void SA() {
int x = calc();
for (double t = 1e3; t >= 1e-7; t *= 0.9985) {
int u = rand() % (n - 1) + 2;
int v = rand() % (n - 1) + 2;
while (v == u) v = rand() % (n - 1) + 2; swap(c[u], c[v]);
int y = calc(); if (y < x) { x = y; continue; } int d = x - y;
if ((db)exp(d / t) > (db)rand() / RAND_MAX) { x = y; continue; }
swap(c[u], c[v]);
}
}
void sub() {
srand(time(0)); read(n);
rep(i, 1, n) read(a[i]);
rep(i, 1, n) c[i] = a[i] - a[i - 1];
while ((db)clock() / CLOCKS_PER_SEC <= 0.97) SA();
printf("%lld\n", calc());
}
signed main() {
// freopen("ex_variance4.in", "r", stdin);
// read(T);
while (T -- ) sub();
return 0;
}
详细
Pretests
Final Tests
Test #1:
score: 4
Accepted
time: 969ms
memory: 6068kb
input:
4 2 3 4 8
output:
83
result:
ok single line: '83'
Test #2:
score: 4
Accepted
time: 974ms
memory: 6120kb
input:
4 1 1 3 6
output:
51
result:
ok single line: '51'
Test #3:
score: 4
Accepted
time: 974ms
memory: 6020kb
input:
4 5 5 6 10
output:
59
result:
ok single line: '59'
Test #4:
score: 4
Accepted
time: 974ms
memory: 6220kb
input:
10 1 10 19 22 31 32 32 36 39 39
output:
9604
result:
ok single line: '9604'
Test #5:
score: 4
Accepted
time: 974ms
memory: 6252kb
input:
10 5 6 13 21 27 27 30 32 34 37
output:
6956
result:
ok single line: '6956'
Test #6:
score: 4
Accepted
time: 973ms
memory: 6232kb
input:
14 2 2 4 4 8 8 8 10 11 11 11 16 18 18
output:
2208
result:
ok single line: '2208'
Test #7:
score: 4
Accepted
time: 971ms
memory: 6068kb
input:
15 1 3 5 7 7 10 10 10 10 11 13 13 18 18 20
output:
4076
result:
ok single line: '4076'
Test #8:
score: 4
Accepted
time: 973ms
memory: 6176kb
input:
15 1 1 2 4 4 6 6 9 9 11 11 14 16 16 18
output:
3524
result:
ok single line: '3524'
Test #9:
score: 4
Accepted
time: 969ms
memory: 6256kb
input:
20 70 75 87 93 93 96 102 111 116 128 142 169 189 194 206 215 215 215 230 240
output:
613931
result:
ok single line: '613931'
Test #10:
score: 4
Accepted
time: 970ms
memory: 5992kb
input:
20 45 56 68 90 111 145 154 155 161 171 176 187 190 196 201 216 222 280 280 280
output:
955084
result:
ok single line: '955084'
Test #11:
score: 4
Accepted
time: 973ms
memory: 6124kb
input:
20 20 52 88 96 102 113 137 144 150 159 185 188 188 188 201 202 229 246 261 273
output:
1301784
result:
ok single line: '1301784'
Test #12:
score: 0
Wrong Answer
time: 974ms
memory: 6260kb
input:
20 48 58 63 69 83 83 89 112 118 121 132 139 156 169 169 169 181 201 208 238
output:
742859
result:
wrong answer 1st lines differ - expected: '742851', found: '742859'
Test #13:
score: 4
Accepted
time: 975ms
memory: 6128kb
input:
50 1 3 3 4 6 6 6 9 10 11 12 13 14 14 14 15 18 21 23 25 25 25 29 30 31 34 34 35 36 41 41 41 42 42 42 47 50 50 51 51 64 64 65 65 66 69 69 69 70 70
output:
329064
result:
ok single line: '329064'
Test #14:
score: 4
Accepted
time: 970ms
memory: 6120kb
input:
50 1 2 2 3 4 5 9 10 14 15 17 17 19 20 22 22 23 24 28 29 29 30 31 31 31 32 34 35 39 39 40 40 41 41 42 42 44 44 45 45 46 47 48 52 53 54 65 66 67 69
output:
393256
result:
ok single line: '393256'
Test #15:
score: 4
Accepted
time: 973ms
memory: 6128kb
input:
50 2 2 5 6 7 7 7 8 9 10 10 10 15 15 15 16 18 18 19 23 23 24 27 27 29 31 32 32 36 36 37 40 43 44 46 46 47 48 50 51 52 52 65 66 66 66 67 67 68 70
output:
336136
result:
ok single line: '336136'
Test #16:
score: 4
Accepted
time: 975ms
memory: 6088kb
input:
100 1 1 2 2 3 3 3 3 4 4 4 4 4 5 5 5 5 5 5 7 7 7 8 8 9 9 9 10 10 10 10 10 11 11 11 12 12 12 12 13 13 13 13 21 21 21 22 22 23 24 24 24 24 25 26 26 26 26 26 27 27 27 28 28 28 28 29 29 30 30 30 31 32 32 32 32 32 33 34 34 34 35 35 35 36 36 37 38 38 38 38 39 39 39 39 39 40 40 40 40
output:
302700
result:
ok single line: '302700'
Test #17:
score: 4
Accepted
time: 966ms
memory: 5988kb
input:
100 1 1 2 2 2 2 2 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 7 7 7 8 8 8 9 10 10 11 11 11 11 12 12 12 13 13 13 21 21 21 21 22 22 22 23 23 24 24 24 24 24 25 26 26 26 26 26 26 26 27 27 28 28 28 28 28 29 29 29 30 30 30 30 31 31 31 31 31 32 33 34 34 35 35 35 35 35 35 37 37 38 38 38 38 39
output:
276964
result:
ok single line: '276964'
Test #18:
score: 0
Wrong Answer
time: 974ms
memory: 5992kb
input:
100 1 1 1 2 3 3 3 3 3 3 4 5 5 5 6 6 6 6 7 7 7 7 7 8 8 8 8 9 9 10 10 10 11 11 13 13 13 13 21 21 21 22 22 22 22 23 23 23 23 23 23 23 24 24 24 25 25 26 27 27 27 27 28 28 28 29 29 29 29 30 30 30 31 32 32 32 33 33 34 34 34 34 34 35 35 36 37 37 37 37 37 37 38 38 38 38 39 40 40 40
output:
302819
result:
wrong answer 1st lines differ - expected: '302700', found: '302819'
Test #19:
score: 4
Accepted
time: 978ms
memory: 6092kb
input:
400 1 1 2 2 3 4 4 5 5 6 6 6 6 7 8 8 8 10 10 10 11 11 11 11 11 11 12 12 12 12 13 14 14 15 15 15 16 16 17 18 18 18 19 20 22 23 29 29 30 31 31 32 32 32 33 33 34 34 35 35 35 36 37 37 37 37 37 37 37 37 37 38 38 38 38 38 38 39 39 40 41 42 46 47 48 49 49 50 50 50 51 51 52 52 53 53 53 53 55 56 56 56 58 58 5...
output:
266737600
result:
ok single line: '266737600'
Test #20:
score: 4
Accepted
time: 973ms
memory: 6072kb
input:
400 1 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 6 6 7 8 9 10 10 16 17 18 19 19 20 20 20 20 20 21 22 23 23 24 25 25 25 25 25 25 25 25 26 26 27 27 28 29 29 29 29 29 29 29 30 30 30 30 30 30 30 30 30 30 30 31 31 32 33 34 34 35 35 35 35 37 37 38 38 38 38 39 39 40 43 44 45 45 45 45 46 47 48 49 50 50 50 58 59 59...
output:
271813084
result:
ok single line: '271813084'
Test #21:
score: 4
Accepted
time: 975ms
memory: 6120kb
input:
400 1 1 1 2 3 3 4 5 5 5 5 5 5 5 6 6 6 7 7 9 9 9 10 11 12 12 12 13 13 14 14 15 16 17 17 18 18 18 18 18 18 19 20 20 20 21 21 22 23 23 24 25 26 27 27 28 28 30 30 31 31 32 33 33 33 34 34 34 35 35 35 36 36 36 37 38 39 39 40 40 41 41 41 42 42 42 42 43 44 45 46 46 46 46 47 47 48 48 49 50 51 51 52 53 58 58 ...
output:
263380775
result:
ok single line: '263380775'
Test #22:
score: 0
Wrong Answer
time: 974ms
memory: 6228kb
input:
400 1 2 3 4 5 5 5 14 15 15 15 16 16 16 17 18 18 18 18 19 19 19 20 21 26 27 28 29 29 29 29 29 30 30 31 31 31 31 32 33 34 34 34 35 36 37 37 37 38 39 40 40 41 41 43 44 44 45 46 46 46 47 47 48 49 50 50 50 51 52 52 55 55 55 56 57 57 57 58 58 58 59 59 59 59 60 62 63 64 64 64 65 65 65 66 66 67 68 68 68 69 ...
output:
256248636
result:
wrong answer 1st lines differ - expected: '256248151', found: '256248636'
Test #23:
score: 0
Time Limit Exceeded
input:
10000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1123686239
result:
Test #24:
score: 0
Time Limit Exceeded
input:
10000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1140087536
result:
Test #25:
score: 0
Time Limit Exceeded
input:
10000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1639404775