Submission #1260514
Source Code Expand
#include<iostream> #include<vector> using namespace std; pair<vector<pair<int, int>>, int>dp[100005]; int n; int solve(int pos) { if (pos == 0)return 0; if (dp[pos].second >= 1)return dp[pos].second; int minx = 100000; vector<pair<int, int>>minid; for (int i = 0; i < 20; i++) { if ((1 << i) > pos)continue; int G = solve(pos - (1 << i)); if (G + 1 < minx) { minx = G + 1; minid = dp[pos - (1 << i)].first; minid.push_back(make_pair(i, -1)); } } for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { if ((1 << i) >= pos || (1 << j) >= pos || (1 << i) + (1 << j) <= pos)continue; int G = solve((1 << i) + (1 << j) - pos); if (G + 2 < minx) { minx = G + 2; minid = dp[(1 << i) + (1 << j) - pos].first; minid.push_back(make_pair(i, j)); } } } dp[pos] = make_pair(minid, minx); return minx; } int sum(int pos, int L, int R) { if (pos == dp[n].first.size())return 0; int B1 = dp[n].first[pos].first, B2 = dp[n].first[pos].second; if (B2 == -1) { cout << "? " << L << ' ' << L + (1 << B1) << endl; int s; cin >> s; return s + sum(pos + 1, L + (1 << B1), R); } else { cout << "? " << L << ' ' << L + (1 << B1) << endl; int s; cin >> s; cout << "? " << R - (1 << B2) << ' ' << R << endl; int t; cin >> t; return s + t - sum(pos + 1, R - (1 << B2), L + (1 << B1)); } } int main() { cin >> n; solve(n); reverse(dp[n].first.begin(), dp[n].first.end()); cout << sum(0, 0, n) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Array Sum |
User | E869120 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1489 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:42:58: error: ‘reverse’ was not declared in this scope solve(n); reverse(dp[n].first.begin(), dp[n].first.end()); ^