求问
  • 板块灌水区
  • 楼主封禁用户
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/7/3 22:45
  • 上次更新2024/7/4 10:33:53
查看原帖
求问
750292
封禁用户楼主2024/7/3 22:45

这题快读会爆,但是正常 cin 就可以 A ,为什么?

#include <bits/stdc++.h>
#define f(i ,m ,n ,x) for (int i = (m) ;i <= (n) ;i += (x))
using namespace std ;
const int N = 2e4+ 7 ;
const int M = 47 ; 
int n ,s[N] ,t[N] ;
long long a[N] ,b[N] ,c[N] ,dp[N][M][M] ; 
template <typename T> inline void read (T &x) {
		x = 0 ;
		char ch = getchar () ;
		while (! isdigit (ch)) {
			ch = getchar () ;
		}
		while (isdigit (ch)) {
			x = (x << 1) + (x << 3) + (ch xor 48) ;
			ch = getchar () ;
		}
	}
inline long long dfs (int u ,int x ,int y) {
	if (u > n - 1) return c[u - n + 1] * (a[u - n + 1] + x) * (b[u - n + 1] + y) ;
	if (dp[u][x][y] != dp[0][0][0]) return dp[u][x][y] ;
    return dp[u][x][y] = min (dfs (s[u] ,x ,y) + dfs(t[u] ,x ,y + 1) ,dfs(s[u] ,x + 1 ,y) + dfs (t[u] ,x ,y)) ;
}
int main () {
 	read (n) ;
 	memset (dp ,63 ,sizeof (dp)) ;
	f (i ,1 ,n - 1 ,1) {
		read (s[i]) ,read (t[i]) ;
		if (s[i] < 0) s[i] = n - s[i] - 1 ;
		if (t[i] < 0) t[i] = n - t[i] - 1 ;
	}
	f (i ,1 ,n ,1) {
		read (a[i]) ,read (b[i]) ,read (c[i]) ;
	}
    cout << dfs (1 ,0 ,0) << '\n' ;
    return 0 ;
}
2024/7/3 22:45
加载中...