Submission #674135

#TimeUsernameProblemLanguageResultExecution timeMemory
674135QwertyPiShell (info1cup18_shell)C++14
0 / 100
95 ms49748 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1e6 + 11; vector<int> G[MAXN]; bool vis[MAXN]; vector<int> tp; int n, m, p; void dfs(int v){ vis[v] = true; for(auto i : G[v]){ if(!vis[i]) dfs(i); } tp.push_back(v); } int dp[MAXN], to[MAXN]; int32_t main(){ cin.tie(0); cout.tie(0)->sync_with_stdio(false); cin >> n >> m >> p; vector<int> v; v.push_back(1); for(int i = 0; i < p; i++){ int k; cin >> k; if(k == 1){ if(i == 0 || v.size() == 1) continue; cout << 0 << endl; return 0; } if(v.size() && k == v.back()) continue; v.push_back(k); } if(v.back() != n) v.push_back(n); vector<pair<int, int>> vp, vp2; for(int i = 0; i < m; i++){ int u, v; cin >> u >> v; vp.push_back({u, v}); G[u].push_back(v); } dfs(1); reverse(tp.begin(), tp.end()); for(int i = 0; i < tp.size(); i++){ to[tp[i]] = i + 1; } for(int i = 0; i <= n; i++){ to[i] = i; } vector<int> d; d.push_back(0); for(int i = 0; i < v.size(); i++){ if(to[v[i]] == 0){ cout << 0 << endl; return 0; } if(i != 0 && to[v[i - 1]] > to[v[i]]){ cout << 0 << endl; return 0; } d.push_back(to[v[i]]); } for(auto i : vp){ if(to[i.fi] == 0 || to[i.se] == 0) continue; int f = to[i.fi], t = to[i.se]; if(t > *upper_bound(d.begin(), d.end(), f)) continue; vp2.push_back({f, t}); } sort(vp2.begin(), vp2.end()); dp[1] = 1; for(auto i : vp2){ dp[i.se] = (dp[i.fi] + dp[i.se]) % MOD; } cout << dp[(int) tp.size() - 1] << endl; }

Compilation message (stderr)

shell.cpp: In function 'int32_t main()':
shell.cpp:45:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for(int i = 0; i < tp.size(); i++){
      |                 ~~^~~~~~~~~~~
shell.cpp:52:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...