Submission #372239

#TimeUsernameProblemLanguageResultExecution timeMemory
372239gustasonTravels (LMIO17_keliones)C++11
8 / 100
13 ms620 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define int ll const int mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> add(n); for(int i = 0; i < n; i++) { cin >> add[i]; } bool adj[n][n]; for(int i = 0; i < n; i++) { for(int j = i+1; j < n; j++) { adj[i][j] = true; } } for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; adj[a][b] = false; } vector<ll> cnt(n, 0), sum(n, 0); for(int i = 0; i < n; i++) { cnt[i] %= mod; ll cnts = (cnt[i] * add[i]) % mod; sum[i] += cnts; for(int j = i+1; j < n; j++) { if (!adj[i][j]) continue; cnt[j] += (cnt[i] + 1); cnt[j] %= mod; sum[j] += (sum[i] + add[i]); } } ll ans = 0; for(int i = 0; i < n; i++) { ans += sum[i]; ans %= mod; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...