Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
140559 陈志轩 金矿 C++ 通过 100 0 MS 316 KB 947 2024-03-30 15:53:06

Tests(5/5):


#include<bits/stdc++.h> #define int long long using namespace std; int a[1005],b[1005],id[1005],dp[1005]; vector <int> v[1005],vec[1005]; signed main(){ int n; cin>>n; for (int i = 1;i <= n;i++){ cin>>a[i]; } string s; for (int i = 1;i <= n;i++){ cin>>id[i]; getline(cin,s); //cout<<"\n"<<s<<'\n'; int num = 0; s += ' '; for (int j = 0;j < s.size();j++){ if (s[j] >= '0' && s[j] <= '9'){ num = num * 10 + s[j] - 48; } else{ if (num != 0){ v[id[i]].push_back(num); num = 0; } } } } for (int i = 1;i <= n;i++){ b[i] = a[id[i]]; for (int j = 0;j < v[id[i]].size();j++){ vec[v[id[i]][j]].push_back(i); } } int ans = 0; for (int i = 1;i <= n;i++){ dp[i] = b[i]; for (int j = 0;j < vec[i].size();j++){ if (vec[i][j] < i){ dp[i] = max(dp[i],dp[vec[i][j]] + b[i]); } } ans = max(ans,dp[i]); } cout<<ans; return 0; }


测评信息: