Submission #204997

# Submission time Handle Problem Language Result Execution time Memory
204997 2020-02-27T16:38:14 Z Haunted_Cpp Shell (info1cup18_shell) C++17
55 / 100
1000 ms 15868 KB
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
 
#define FOR(i, a, b) for (int i = a; i < (int) b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define f first
#define s second
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
 
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};

const int N = 1500 + 5;
const int M = 1500 + 5;
const int MOD = 1e9 + 7;

int n, m, k, streak [N];
int dp [N][M];
vvi g (N);

void add (int &a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
}

int solve (int node, int match) {
  if (node == n - 1) return (match == k);
  if (~dp[node][match]) return dp[node][match];
  dp[node][match] = 0;
  int target = (match < k ? streak[match] : -1); 
  GO (to, g[node]) add (dp[node][match], solve (to, match + (to == target)));
  return dp[node][match];
} 

int main () {
  scanf ("%d %d %d", &n, &m, &k);
  memset (dp, -1, sizeof(dp));
  F0R (i, k) {
    scanf ("%d", &streak[i]);
    --streak[i];
  }
  F0R (i, m) {
    int st, et;
    scanf ("%d %d", &st, &et);
    --st; --et;
    g[st].eb(et);
  } 
  printf("%d\n", solve (0, streak[0] == 0 ? 1 : 0));
  return 0;
}

Compilation message

shell.cpp: In function 'int main()':
shell.cpp:54:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d %d", &n, &m, &k);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
shell.cpp:57:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d", &streak[i]);
     ~~~~~~^~~~~~~~~~~~~~~~~~
shell.cpp:62:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &st, &et);
     ~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9208 KB Output is correct
2 Correct 9 ms 9208 KB Output is correct
3 Correct 9 ms 9208 KB Output is correct
4 Correct 9 ms 9208 KB Output is correct
5 Correct 9 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9208 KB Output is correct
2 Correct 9 ms 9208 KB Output is correct
3 Correct 9 ms 9208 KB Output is correct
4 Correct 9 ms 9208 KB Output is correct
5 Correct 9 ms 9208 KB Output is correct
6 Correct 9 ms 9208 KB Output is correct
7 Correct 45 ms 9464 KB Output is correct
8 Correct 36 ms 9336 KB Output is correct
9 Correct 17 ms 9464 KB Output is correct
10 Correct 24 ms 9464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9212 KB Output is correct
2 Correct 971 ms 11976 KB Output is correct
3 Correct 116 ms 11896 KB Output is correct
4 Correct 120 ms 11872 KB Output is correct
5 Correct 179 ms 11244 KB Output is correct
6 Correct 255 ms 15868 KB Output is correct
7 Execution timed out 1088 ms 15860 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9208 KB Output is correct
2 Correct 9 ms 9208 KB Output is correct
3 Correct 9 ms 9208 KB Output is correct
4 Correct 9 ms 9208 KB Output is correct
5 Correct 9 ms 9208 KB Output is correct
6 Correct 9 ms 9208 KB Output is correct
7 Correct 45 ms 9464 KB Output is correct
8 Correct 36 ms 9336 KB Output is correct
9 Correct 17 ms 9464 KB Output is correct
10 Correct 24 ms 9464 KB Output is correct
11 Correct 11 ms 9212 KB Output is correct
12 Correct 971 ms 11976 KB Output is correct
13 Correct 116 ms 11896 KB Output is correct
14 Correct 120 ms 11872 KB Output is correct
15 Correct 179 ms 11244 KB Output is correct
16 Correct 255 ms 15868 KB Output is correct
17 Execution timed out 1088 ms 15860 KB Time limit exceeded