编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#24205 | #1144. ddd和猴子 | Compile Error | 0 | 0 ms | 0 K | C++ / 1.9 K | Rhodoks | 2020-04-17 23:08:51 |
#include <bits/stdc++.h>
#define DB double
#define LL long long
#define MST(a, b) memset((a), (b), sizeof(a))
#define MRK() cout << "Mark" << endl;
#define WRT(x) cout << #x << " = " << (x) << endl;
#define MAXN 5010
#define MAXM 410000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5
#define _ 0
using namespace std;
string sufin(".in");
string sufout(".out");
void fileIO(int id) {
freopen((to_string(id) + sufin).c_str(), "r", stdin);
freopen((to_string(id) + sufout).c_str(), "w", stdout);
}
vector<int> g[MAXN];
int pool[MAXN][MAXN << 1];
int *dp[MAXN];
int n;
int col[MAXN], size[MAXN];
int cnt[2];
void init() {
int x, y;
cin >> n;
MST(cnt, 0);
for (int i = 1; i <= n; i++) {
dp[i] = pool[i] + MAXN;
g[i].clear();
}
for (int i = 1; i < n; i++) {
scanf("%d%d", &x, &y);
g[x].push_back(y);
g[y].push_back(x);
}
col[1] = -1;
}
void dfs(int pos, int f) {
col[pos] = -col[f];
cnt[(col[pos] + 1) / 2]++;
for (auto p : g[pos])
if (p != f) {
dfs(p, pos);
size[pos] += size[p];
}
}
void clear(int *p, int n) {
for (int i = -n; i <= n; i++) p[i] = -INF;
}
int tpool[MAXN << 1];
int *tmp = tpool + MAXN;
void work(int pos, int f) {
int mx = -INF;
size[pos] = 1;
clear(dp[pos], size[pos]);
dp[pos][col[pos]] = 0;
for (auto p : g[pos])
if (p != f) {
work(p, pos);
clear(tmp, size[pos] + size[p]);
for (int i = -size[pos]; i <= size[pos]; i++)
for (int j = -size[p]; j <= size[p]; j++) tmp[i + j] = max(tmp[i + j], dp[pos][i] + dp[p][j]);
size[pos] += size[p];
for (int i = -size[pos]; i <= size[pos]; i++) dp[pos][i] = tmp[i];
}
for (int i = -size[pos]; i <= size[pos]; i++) dp[pos][0] = max(dp[pos][0], dp[pos][i] + i * i);
}
void work() {
init();
dfs(1, 1);
work(1, 1);
cout << (dp[1][0] - n);
// WRT(cnt[0]);
// WRT(cnt[1]);
}
int main() {
for (int i = 1; i <= 10; i++) {
fileIO(i);
work();
}
return ~~(0 ^ _ ^ 0);
}
编译信息
/sandbox/1/a.cpp: In function 'void fileIO(int)':
/sandbox/1/a.cpp:24:11: error: 'to_string' was not declared in this scope
freopen((to_string(id)+sufin).c_str(),"r",stdin);
^~~~~~~~~
/sandbox/1/a.cpp:24:11: note: suggested alternative: 'towctrans'
freopen((to_string(id)+sufin).c_str(),"r",stdin);
^~~~~~~~~
towctrans
/sandbox/1/a.cpp: In function 'void dfs(int, int)':
/sandbox/1/a.cpp:58:12: error: 'p' does not name a type
for (auto p:g[pos])
^
/sandbox/1/a.cpp:63:4: error: expected ';' before '}' token
}
^
;
}
~
/sandbox/1/a.cpp:64:1: error: expected primary-expression before '}' token
}
^
/sandbox/1/a.cpp:63:4: error: expected ';' before '}' token
}
^
;
}
~
/sandbox/1/a.cpp:64:1: error: expected primary-expression before '}' token
}
^
/sandbox/1/a.cpp:63:4: error: expected ')' before '}' token
}
^
)
}
~
/sandbox/1/a.cpp:58:6: note: to match this '('
for (auto p:g[pos])
^
/sandbox/1/a.cpp:64:1: error: expected primary-expression before '}' token
}
^
/sandbox/1/a.cpp: In function 'void work(int, int)':
/sandbox/1/a.cpp:81:12: error: 'p' does not name a type
for (auto p:g[pos])
^
/sandbox/1/a.cpp:92:4: error: expected ';' before 'for'
}
^
;
for (int i=-size[pos];i<=size[pos];i++)
~~~
/sandbox/1/a.cpp:93:2: error: expected primary-expression before 'for'
for (int i=-size[pos];i<=size[pos];i++)
^~~
/sandbox/1/a.cpp:92:4: error: expected ';' before 'for'
}
^
;
for (int i=-size[pos];i<=size[pos];i++)
~~~
/sandbox/1/a.cpp:93:2: error: expected primary-expression before 'for'
for (int i=-size[pos];i<=size[pos];i++)
^~~
/sandbox/1/a.cpp:92:4: error: expected ')' before 'for'
}
^
)
for (int i=-size[pos];i<=size[pos];i++)
~~~
/sandbox/1/a.cpp:81:6: note: to match this '('
for (auto p:g[pos])
^
/sandbox/1/a.cpp: In function 'void init()':
/sandbox/1/a.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
~~~~~^~~~~~~~~~~~~~