답안 #527232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527232 2022-02-17T04:03:18 Z maomao90 Calvinball championship (CEOI15_teams) C++17
50 / 100
1000 ms 2120 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)

template<class T>
inline bool mxto(T &a, T b) {return a < b ? a = b, 1 : 0;}
template<class T>
inline bool mnto(T &a, T b) {return a > b ? a = b, 1 : 0;}

typedef long long ll;
#define FI first
#define SE second
#define MP make_pair
typedef pair<int, int> ii;
#define pb push_back
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<ii> vii;
#define MT make_tuple
typedef tuple<int, int, int> iii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

#define INF 1000000005
#define LINF 1000000000000000005ll
#define MAXN 10005
#define MOD 1000007

struct hsh {
	int operator() (const iii& o) const {
		auto [a, b, c] = o;
		return ((a + 231) << 3821) + ((b + 123) << 236) + (c + 93);
	}
};

int n;
int a[MAXN];

unordered_map<iii, int, hsh> memo;
int dp(int i, int j, bool same) {
	if (i >= n) {
		return 1;
	}
	if (memo.find(MT(i, j, same)) != memo.end()) {
		return memo[MT(i, j, same)];
	}
	int res = 0;
	if (same) {
		REP (k, 1, min(j + 1, a[i])) {
			res += dp(i + 1, j, 0);
			if (res >= MOD) {
				res -= MOD;
			}
		}
		if (a[i] <= j + 1) {
			res += dp(i + 1, max(j, a[i]), 1);
			if (res >= MOD) {
				res -= MOD;
			}
		}
	} else {
		REP (k, 1, j + 1) {
			res += dp(i + 1, j, 0);
			if (res >= MOD) {
				res -= MOD;
			}
		}
		res += dp(i + 1, j + 1, 0);
		if (res >= MOD) {
			res -= MOD;
		}
	}
	return memo[MT(i, j, same)] = res;
}

int main() {
#ifndef DEBUG
	ios::sync_with_stdio(0), cin.tie(0);
#endif
	cin >> n;
	REP (i, 0, n) {
		cin >> a[i];
	}
	cout << dp(0, 0, 1) << '\n';
	return 0;
}

Compilation message

teams.cpp: In member function 'int hsh::operator()(const iii&) const':
teams.cpp:36:21: warning: left shift count >= width of type [-Wshift-count-overflow]
   36 |   return ((a + 231) << 3821) + ((b + 123) << 236) + (c + 93);
      |           ~~~~~~~~~~^~~~~~~
teams.cpp:36:43: warning: left shift count >= width of type [-Wshift-count-overflow]
   36 |   return ((a + 231) << 3821) + ((b + 123) << 236) + (c + 93);
      |                                 ~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 544 KB Output is correct
2 Correct 216 ms 520 KB Output is correct
3 Correct 222 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1072 ms 1100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1098 ms 2096 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 1656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 2120 KB Time limit exceeded
2 Halted 0 ms 0 KB -