답안 #503046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503046 2022-01-07T04:17:32 Z ismoilov 바이오칩 (IZhO12_biochips) C++14
100 / 100
268 ms 402372 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
const int maxx = 2e5+5;
int a[maxx], b[maxx];
int d[maxx][505];
vector <int> g[maxx];
int n, m, r, cnt = 0;
void dfs(int v){
	b[v] = cnt;
	for(auto it : g[v])
		dfs(it);
	fpp(i,1,m)
		d[cnt+1][i] = max(d[cnt][i], d[b[v]][i - 1] + a[v]);
	cnt ++;
}

void S()
{
	cin >> n >> m;
	fpp(i,1,n){
		int x;
		cin >> x >> a[i];
		if(x == 0)
			r = i;
		else
			g[x].push_back(i);
	}
	fpp(i,1,m)
		d[0][i] = -maxx;
	dfs(r);
	cout << d[n][m];
}
int main()
{
	IOS;
	S();
}

Compilation message

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
biochips.cpp:19:2: note: in expansion of macro 'fpp'
   19 |  fpp(i,1,m)
      |  ^~~
biochips.cpp: In function 'void S()':
biochips.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
biochips.cpp:27:2: note: in expansion of macro 'fpp'
   27 |  fpp(i,1,n){
      |  ^~~
biochips.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
biochips.cpp:35:2: note: in expansion of macro 'fpp'
   35 |  fpp(i,1,m)
      |  ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 2 ms 5196 KB Output is correct
4 Correct 12 ms 22988 KB Output is correct
5 Correct 13 ms 25000 KB Output is correct
6 Correct 13 ms 25036 KB Output is correct
7 Correct 215 ms 300180 KB Output is correct
8 Correct 179 ms 300208 KB Output is correct
9 Correct 215 ms 364572 KB Output is correct
10 Correct 268 ms 402372 KB Output is correct