Problem Info
Bessie’s Birthday Buffet: USACO
My Work
/*
This code belongs to Aadit Ambadkar
Date: 2021-10-16 17:31:56
Problem: Buffet
*/
#include <bits/stdc++.h>
using namespace::std;
typedef long long ll;
#define F0R(i, n) for (int i = 0; i < n; i++)
#define R0F(i, n) for (int i = n-1; i >= 0; i--)
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0)
#define MOD 1000000007
#define FF first
#define SS second
const int MAXN = 1005;
int n;
ll E;
vector<int> adj[MAXN];
ll qual[MAXN];
int SARR[MAXN];
ll dist[MAXN][MAXN];
struct CCMP {
bool operator()(int a, int b) {
return qual[a]<qual[b];
}
};
int main() {
freopen("buffet.in", "r", stdin);
freopen("buffet.out", "w", stdout);
fastio;
cin >> n;
cin >> E;
F0R(i, n) {
int __;
cin >> qual[i] >> __;
F0R(j, __) {
int x; cin >> x;
adj[i].pb(x-1);
}
SARR[i]=i;
}
F0R(i, n) {
F0R(j, n) {
dist[i][j]=1e14;
}
}
F0R(i, n) {
queue<pair<int, ll>> q;
q.push({i, 0});
bool vis[n];
memset(vis, false, sizeof(vis));
while (!q.empty()) {
auto top = q.front(); q.pop();
if (vis[top.FF]) continue;
vis[top.FF]=true;
dist[i][top.FF]=top.SS;
for (auto next : adj[top.FF]) {
q.push({next, top.SS+1});
}
}
}
sort(SARR, SARR+n, CCMP());
ll dp[n];
F0R(i, n) {
int x = SARR[i];
dp[x]=qual[x];
F0R(j, n) {
int y = SARR[j];
if (qual[y]<qual[x]) dp[x]=max(dp[x], qual[x]+dp[y]-E*dist[x][y]);
// else break;
}
}
cout << dp[SARR[n-1]] << "\n";
}
Standard DP Sol
What I’ve Tried
I’ve tried pretty much everything except copy pasting the testcases. I’ve set everything to long longs, etc.
Question
I am getting TC 4 and 10 wrong, could I have a hint as to why?