Submission #521336

# Submission time Handle Problem Language Result Execution time Memory
521336 2022-02-01T18:38:09 Z raid Shell (info1cup18_shell) C++17
100 / 100
773 ms 48228 KB
#include <iostream>
#include <iostream>
#include <vector>
#define fin cin
#define fout cout

using namespace std;

const int MAXN = 1000005;
const int MOD = 1e9 + 7;

using ll = long long;

vector<int> G[MAXN];
bool viz[MAXN];

vector<int> req_vrt;
int dp[MAXN];
vector<int> vrt;

void sort_top( int u ) {
  viz[u] = true;
  for ( auto v : G[u] ) {
    if ( !viz[v] ) {
      sort_top( v );
    }
  }
  vrt.push_back(u);
}
 
vector<pair<int, int>> rng;

int main() {
  int n, m, p, x, y;
 
  fin >> n >> m >> p;
  req_vrt.push_back(1);
  for ( int i = 0; i < p; ++i ) {
    fin >> x;
    if ( i == 0 && x == 1 ) continue;
    req_vrt.push_back(x);
  }
  if ( req_vrt.back() != n ) {
    req_vrt.push_back(n);
  }
  while ( m-- ) {  
    fin >> x >> y;
    G[y].push_back( x );
  }
  for ( int i = 1; i <= n; ++i ) {
    if ( !viz[i] ) {
      sort_top( i );
    }
  }
  int now = 0, prv = -1;
  p = req_vrt.size() - 1;
  for ( int i = 0; i < n; ++i ) {
    if ( now <= p && vrt[i] == req_vrt[now] ) {
      ++now;
      if ( prv != -1 ) rng.push_back( {prv, i} );
      prv = i;
    }
  }
  if ( now <= p ) {
    fout << 0;
    return 0;
  }
  ll res = 1;
  for ( int i = 0; i < rng.size(); ++i ) {
    dp[vrt[rng[i].first]] = 1;
    for ( int j = rng[i].first + 1; j <= rng[i].second; ++j ) {
      for ( auto v : G[vrt[j]] ) {
        dp[vrt[j]] = (dp[vrt[j]] + dp[v]) % MOD;
      }
    }
    res = (res * dp[vrt[rng[i].second]]) % MOD;
    for ( int j = rng[i].first; j <= rng[i].second; ++j ) {
      dp[vrt[j]] = 0;
    }
  }
  fout << res;
  return 0;
}

Compilation message

shell.cpp: In function 'int main()':
shell.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for ( int i = 0; i < rng.size(); ++i ) {
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23868 KB Output is correct
2 Correct 13 ms 23780 KB Output is correct
3 Correct 12 ms 23788 KB Output is correct
4 Correct 12 ms 23680 KB Output is correct
5 Correct 12 ms 23740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23868 KB Output is correct
2 Correct 13 ms 23780 KB Output is correct
3 Correct 12 ms 23788 KB Output is correct
4 Correct 12 ms 23680 KB Output is correct
5 Correct 12 ms 23740 KB Output is correct
6 Correct 14 ms 23756 KB Output is correct
7 Correct 22 ms 24132 KB Output is correct
8 Correct 17 ms 23880 KB Output is correct
9 Correct 26 ms 24180 KB Output is correct
10 Correct 28 ms 24228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 243 ms 30748 KB Output is correct
3 Correct 275 ms 30740 KB Output is correct
4 Correct 222 ms 30724 KB Output is correct
5 Correct 155 ms 28384 KB Output is correct
6 Correct 583 ms 40756 KB Output is correct
7 Correct 527 ms 40848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23868 KB Output is correct
2 Correct 13 ms 23780 KB Output is correct
3 Correct 12 ms 23788 KB Output is correct
4 Correct 12 ms 23680 KB Output is correct
5 Correct 12 ms 23740 KB Output is correct
6 Correct 14 ms 23756 KB Output is correct
7 Correct 22 ms 24132 KB Output is correct
8 Correct 17 ms 23880 KB Output is correct
9 Correct 26 ms 24180 KB Output is correct
10 Correct 28 ms 24228 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 243 ms 30748 KB Output is correct
13 Correct 275 ms 30740 KB Output is correct
14 Correct 222 ms 30724 KB Output is correct
15 Correct 155 ms 28384 KB Output is correct
16 Correct 583 ms 40756 KB Output is correct
17 Correct 527 ms 40848 KB Output is correct
18 Correct 773 ms 48228 KB Output is correct
19 Correct 733 ms 47556 KB Output is correct
20 Correct 678 ms 45380 KB Output is correct
21 Correct 274 ms 32692 KB Output is correct
22 Correct 732 ms 45648 KB Output is correct