This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |