求问

灌水区

Melo.VVちゃん @ 2024-07-03 22:45:49

这题快读会爆,但是正常 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 ;
}

by Melo.VVちゃん @ 2024-07-03 22:50:54

破案了,我的快读读入负数会自动去掉负号


|