답안 #673548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673548 2022-12-21T03:49:27 Z Cutebol 바이오칩 (IZhO12_biochips) C++17
50 / 100
245 ms 524288 KB
#include <bits/stdc++.h>
 
using namespace std;
 
void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define Scaramouche ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
#define int long long
#define itn int
#define endl "\n"
#define ff first
#define ss second
   
const int N = 2e5 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e9 ;

int n , m , s , timer = 1 ;
int a[N] , p[N] , b[N] , tin[N] ;
int dp[N][505] ;
vector <int> g[N] ;

void dfs( int v ){
	int tt = timer ;
	for ( auto to : g[v] ) dfs(to) ;
	tin[timer] = tt ;
	b[timer] = a[v] ;
	timer ++ ;
}

void solve(){
	
	cin >> n >> m ;
	for ( int i = 1 ; i <= n ; i ++ ){
		cin >> p[i] >> a[i] ;
		if (!p[i]) s = i ;
		else g[p[i]].push_back(i) ;
	}
	dfs(s) ;
	for ( int i = 0 ; i <= n ; i ++ ) {
		for ( int j = 1 ; j <= m ; j ++ ) {
			dp[i][j] = -inf ;
		}
	}
	for ( int i = 1 ; i <= n ; i ++ ){
		for ( int j = 1 ; j <= m ; j ++ ){
			dp[i][j] = max ( dp[i-1][j] , dp[tin[i]-1][j-1] + b[i] ) ;
		}
	}
	cout << dp[n][m] ;
}
 
signed main(){
//  fopn("blocks") ;
    Scaramouche ;
    int t = 1 ;
//    	cin >> t ;
    while ( t -- ) solve() ; 
}

Compilation message

biochips.cpp: In function 'void fopn(std::string)':
biochips.cpp:5:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
biochips.cpp:5:72: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Incorrect 3 ms 5076 KB Output isn't correct
3 Correct 3 ms 5408 KB Output is correct
4 Correct 19 ms 40548 KB Output is correct
5 Correct 21 ms 45136 KB Output is correct
6 Correct 22 ms 45004 KB Output is correct
7 Runtime error 220 ms 524288 KB Execution killed with signal 9
8 Runtime error 213 ms 524288 KB Execution killed with signal 9
9 Runtime error 245 ms 524288 KB Execution killed with signal 9
10 Runtime error 222 ms 524288 KB Execution killed with signal 9