Submission #35664

#TimeUsernameProblemLanguageResultExecution timeMemory
35664UncleGrandpa925Skyscraper (JOI16_skyscraper)C++14
100 / 100
376 ms183548 KiB
/*input 8 35 3 7 1 5 10 2 11 6 4 10 3 6 2 9 3 10 2 3 6 9 */ #include <bits/stdc++.h> using namespace std; #define sp ' ' #define endl '\n' #define fi first #define se second #define mp make_pair #define int long long #define N #define bit(x,y) ((x>>y)&1LL) #define na(x) (#x) << ":" << x ostream& operator << (ostream &os, vector<int>&x) { for (int i = 0; i < x.size(); i++) os << x[i] << sp; return os; } ostream& operator << (ostream &os, pair<int, int> x) { cout << x.fi << sp << x.se << sp; return os; } ostream& operator << (ostream &os, vector<pair<int, int> >&x) { for (int i = 0; i < x.size(); i++) os << x[i] << endl; return os; } int n, lim; vector<int> a; vector<int> b; int dp[105][55][2][2][1005]; const int mod = 1e9 + 7; int cal(int pos, int numcc, bool loc, bool roc, int diff) { if (pos) { diff += a[pos - 1] * (2 * numcc - loc - roc); } if (diff > lim) return 0; if (pos == n) { if (numcc != 1 || !loc || !roc) return 0; if (diff <= lim && numcc == 1 && loc && roc) return 1; return 0; } if (dp[pos][numcc][loc][roc][diff] != -1) { return dp[pos][numcc][loc][roc][diff]; } int &ret = dp[pos][numcc][loc][roc][diff]; ret = 0; // make new if (numcc <= n - pos) { ret += cal(pos + 1, numcc + 1, loc, roc, diff) * (numcc + 1 - loc - roc); // make new loc if (!loc) ret += cal(pos + 1, numcc + 1, 1, roc, diff); // make new roc if (!roc) ret += cal(pos + 1, numcc + 1, loc, 1, diff); } if (numcc) { // push front ret += cal(pos + 1, numcc, loc, roc, diff) * (numcc - loc); // push back ret += cal(pos + 1, numcc, loc, roc, diff) * (numcc - roc); // connect if (numcc >= 2) ret += cal(pos + 1, numcc - 1, loc, roc, diff) * (numcc - 1); // push front loc if (!loc) ret += cal(pos + 1, numcc, 1, roc, diff); // push back roc if (!roc) ret += cal(pos + 1, numcc, loc, 1, diff); } ret %= mod; return ret; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef in1code freopen("1test.inp", "r", stdin); #endif cin >> n >> lim; if (n == 1) { cout << 1 << endl; exit(0); } for (int i = 1; i <= n; i++) { int t; cin >> t; a.push_back(t); } sort(a.begin(), a.end()); for (int i = 0; i < a.size() - 1; i++) { a[i] = a[i + 1] - a[i]; } a.back() = 0; memset(dp, -1, sizeof(dp)); cout << cal(0, 0, 0, 0, 0) << endl; }

Compilation message (stderr)

skyscraper.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<long long int>&)':
skyscraper.cpp:21:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
skyscraper.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<long long int, long long int> >&)':
skyscraper.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:96:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.size() - 1; i++) {
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...