Submission #38171

# Submission time Handle Problem Language Result Execution time Memory
38171 2018-01-02T17:30:41 Z farmersrice Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
93 ms 393856 KB
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly
/*
TASK: hidden
LANG: C++11
*/
using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 10013
#define INF 1000000000000000000LL
#define mp make_pair
#define add push_back
#define remove pop
#define MOD 1000007

int n;
int values[MAXN];
int dp[MAXN][MAXN]; //dp[i][j]: num ways from point i IF the highest number that appears before us is j (implying value of i is at most j + 1)
//dp[i][j] = dp[i + 1][j] * j + dp[i + 1][j + 1]

int solve(int index, int first) {
	if (first < 0 || first > n) return 0;
	if (index == n) return 1;

	if (dp[index][first] != -1) {
		return dp[index][first];
	}

	ll answer = solve(index + 1, first) * first * 1LL + solve(index + 1, first + 1);
	answer %= MOD * 1LL;

	return dp[index][first] = (int) answer;
}

int main() {
	if (fopen("FILENAME.in", "r")) {
		freopen("FILENAME.in", "r", stdin);
		freopen("FILENAME.out", "w", stdout);
	}
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> values[i];
	}	

	for (int i = 0; i < MAXN; i++) {
		for (int j = 0; j < MAXN; j++) {
			dp[i][j] = -1;
		}
	}

	int answer = 0;
	int highestNum = 0;
	for (int i = 0; i < n; i++) {
		highestNum = max(highestNum, values[i]);

		if (highestNum == 1) continue;
		answer += solve(i, highestNum - 2);
		answer %= MOD;
	}

	cout << answer + 1 << endl;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:43:37: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen("FILENAME.in", "r", stdin);
                                     ^
indcyc.cpp:44:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen("FILENAME.out", "w", stdout);
                                       ^
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 393856 KB Integer 186 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 393856 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Correct 89 ms 393856 KB Too short sequence
2 Incorrect 63 ms 393856 KB Wrong answer on graph without induced cycle
# Verdict Execution time Memory Grader output
1 Correct 86 ms 393856 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Correct 76 ms 393856 KB Too short sequence
2 Incorrect 66 ms 393856 KB Wrong answer on graph without induced cycle
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 393856 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 393856 KB Too short sequence
2 Incorrect 73 ms 393856 KB Wrong answer on graph without induced cycle
# Verdict Execution time Memory Grader output
1 Correct 53 ms 393856 KB Too short sequence
2 Correct 69 ms 393856 KB Too short sequence
3 Incorrect 83 ms 393856 KB Wrong answer on graph without induced cycle
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 393856 KB Too short sequence
2 Incorrect 76 ms 393856 KB Wrong answer on graph without induced cycle
# Verdict Execution time Memory Grader output
1 Correct 56 ms 393856 KB Too short sequence
2 Incorrect 76 ms 393856 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -