답안 #204469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204469 2020-02-25T20:59:01 Z staniewzki Calvinball championship (CEOI15_teams) C++14
100 / 100
574 ms 760 KB
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<LL, LL>;
 
template<int mod>
struct mi {
	int val;
	mi() { val = 0; }
	mi(const LL& v) {
		val = (-mod <= v && v <= mod) ? v : v % mod;
		if(val < 0) val += mod;
	}
 
	friend ostream& operator<<(ostream &os, const mi &a) {
		return os << a.val;
	}
	friend istream& operator>>(istream &is, mi &a) {
		return is >> a.val;
	}
 
	friend bool operator==(const mi &a, const mi &b) {
		return a.val == b.val;
	}
	friend bool operator!=(const mi &a, const mi &b) {
		return !(a == b);
	}
	friend bool operator<(const mi &a, const mi &b) {
		return a.val < b.val;
	}
	friend bool operator<=(const mi &a, const mi &b) {
		return a.val <= b.val;
	}
 
	mi operator-() const { return mi(-val); }
	mi& operator+=(const mi &m) {
		if((val += m.val) >= mod) val -= mod;
		return *this;
	}
	mi& operator-=(const mi &m) {
		if((val -= m.val) < 0) val += mod;
		return *this;
	}
	mi& operator*=(const mi &m) {
		val = (LL) val * m.val % mod;
		return *this;
	}
	friend mi qpow(mi a, LL n) {
		if(n == 0) return 1;
		if(n % 2 == 1) return qpow(a, n - 1) * a;
		return qpow(a * a, n / 2);
	}
	friend mi inv(const mi &a) {
		assert(a != 0); return qpow(a, mod - 2);
	}
	mi& operator /=(const mi &m) { 
		return (*this) *= inv(m); 
	}
 
	friend mi operator+(mi a, const mi &b) { return a += b; }
	friend mi operator-(mi a, const mi &b) { return a -= b; }
	friend mi operator*(mi a, const mi &b) { return a *= b; }
	friend mi operator/(mi a, const mi &b) { return a /= b; }
};
using MI = mi<int(1e6 + 7)>;
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	int n;
	cin >> n;
	vector<int> a(n), pref(n + 1);
	REP(i, n) {
		cin >> a[i]; a[i]--;
		pref[i + 1] = max(pref[i], a[i]);
	}
 
	MI ans = min(pref[n - 1] + 1, a[n - 1]) + 1;
	vector<vector<MI>> dp(2, vector<MI>(n + 1));
	REP(j, n) dp[(n - 1) & 1][j] = j + 2, debug(j, dp[n & 1 ^ 1][j]);
	for(int i = n - 2; i >= 0; i--) REP(j, n) {
		int x = i & 1, y = (i + 1) & 1;
		dp[x][j] = dp[y][j + 1] + dp[y][j] * (j + 1);
		debug(i, j, dp[x][j]);
		if(j == pref[i])
			ans += min(a[i], j + 1) * dp[y][j];
	}
	cout << ans << "\n";
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:117:66: warning: right operand of comma operator has no effect [-Wunused-value]
  REP(j, n) dp[(n - 1) & 1][j] = j + 2, debug(j, dp[n & 1 ^ 1][j]);
                                                                  ^
teams.cpp:121:24: warning: statement has no effect [-Wunused-value]
   debug(i, j, dp[x][j]);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 376 KB Output is correct
2 Correct 11 ms 376 KB Output is correct
3 Correct 14 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 573 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 504 KB Output is correct
2 Correct 147 ms 376 KB Output is correct
3 Correct 149 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 571 ms 632 KB Output is correct
2 Correct 573 ms 616 KB Output is correct
3 Correct 574 ms 760 KB Output is correct