結果
問題 | No.1103 Directed Length Sum |
ユーザー | QCFium |
提出日時 | 2020-07-14 19:01:16 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 353 ms / 3,000 ms |
コード長 | 1,834 bytes |
コンパイル時間 | 3,713 ms |
コンパイル使用メモリ | 172,572 KB |
実行使用メモリ | 86,772 KB |
最終ジャッジ日時 | 2023-08-11 14:55:34 |
合計ジャッジ時間 | 6,337 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
7,588 KB |
testcase_01 | AC | 2 ms
7,736 KB |
testcase_02 | AC | 131 ms
86,772 KB |
testcase_03 | AC | 53 ms
59,044 KB |
testcase_04 | AC | 178 ms
40,424 KB |
testcase_05 | AC | 353 ms
71,840 KB |
testcase_06 | AC | 98 ms
32,412 KB |
testcase_07 | AC | 15 ms
12,616 KB |
testcase_08 | AC | 22 ms
15,896 KB |
testcase_09 | AC | 10 ms
10,528 KB |
testcase_10 | AC | 37 ms
20,788 KB |
testcase_11 | AC | 193 ms
46,980 KB |
testcase_12 | AC | 99 ms
32,400 KB |
testcase_13 | AC | 37 ms
20,928 KB |
testcase_14 | AC | 9 ms
9,828 KB |
testcase_15 | AC | 69 ms
26,164 KB |
testcase_16 | AC | 226 ms
53,180 KB |
testcase_17 | AC | 233 ms
54,772 KB |
testcase_18 | AC | 36 ms
20,596 KB |
testcase_19 | AC | 203 ms
50,072 KB |
testcase_20 | AC | 12 ms
11,256 KB |
testcase_21 | AC | 20 ms
15,048 KB |
testcase_22 | AC | 155 ms
41,848 KB |
testcase_23 | AC | 70 ms
27,072 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:36:29: 警告: argument to variable-length array is too large [-Wvla-larger-than=] 36 | std::pair<int, int> hens[n - 1]; | ^~~~ main.cpp:36:29: 備考: limit is 9223372036854775807 bytes, but argument is 18446744073709551608 main.cpp:46:15: 警告: ‘void* memset(void*, int, size_t)’ specified size between 18446744071562068017 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] 46 | memset(used, 0, sizeof(used)); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> struct FastIO { char buf[20000000]; char *ptr = buf; void read() { int size; size = fread(buf, 1, sizeof(buf) - 1, stdin); buf[size] = '\0'; ptr = buf; } FastIO () { read(); } void inc() { ptr++; // if (++ptr == buf + sizeof(buf) || !*ptr) read(); } template<typename Integer> Integer read() { bool neg = false; Integer res = 0; while ((*ptr < '0' || *ptr > '9') && *ptr != '-') inc(); if (*ptr == '-') neg = true, inc(); while (*ptr >= '0' && *ptr <= '9') res = res * 10 + *ptr - '0', inc(); return neg ? -res : res; } } fastio; #define ri fastio.read<int> #define rs64 fastio.read<int64_t> std::vector<std::vector<int> > hen; int main() { int n = ri(); std::pair<int, int> hens[n - 1]; for (int i = 0; i + 1 < n; i++) { hens[i].first = ri() - 1; hens[i].second = ri() - 1; } clock_t r0 = clock(); int degree[n]; memset(degree, 0, sizeof(degree)); bool used[n]; memset(used, 0, sizeof(used)); for (int i = 0; i + 1 < n; i++) { degree[hens[i].first]++; used[hens[i].second] = true; } int root = std::find(used, used + n, 0) - used; hen.resize(n); for (int i = 0; i < n; i++) hen[i].resize(degree[i]); for (auto i : hens) hen[i.first][--degree[i.first]] = i.second; int64_t res = 0; static int que[2][1000000]; static int head[2]; que[0][head[0]++] = root; for (int i = 0; head[i & 1]; i++) { res += (int64_t) i * (i + 1) / 2 * head[i & 1]; int next = (i ^ 1) & 1; head[next] = 0; for (int j = 0; j < head[i & 1]; j++) { memcpy(que[next] + head[next], &hen[que[i & 1][j]][0], sizeof(int) * hen[que[i & 1][j]].size()); head[next] += hen[que[i & 1][j]].size(); } } printf("%d\n", (int) (res % 1000000007)); clock_t r1 = clock(); fprintf(stderr, "took %f ms\n", (double)(r1 - r0) / CLOCKS_PER_SEC * 1000); return 0; }