# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1089727 | quangminh412 | Garaža (COCI17_garaza) | C++14 | 660 ms | 196332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
/*
John Watson
Mua Code nhu mua Florentino !!
*/
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
const int oo = 1e9;
const int maxn = 2e5 + 9;
struct Query
{
int l, r;
Query() = default;
Query(int l, int r) : l(l), r(r) {}
bool operator < (Query &other)
{
if (l == other.l) return r < other.r;
return l < other.l;
}
};
int n, q;
int b[maxn], pre[maxn];
vector<Query> queries;
int segment(int l, int r) { return pre[r] - pre[l - 1]; }
signed main()
{
if (fopen("NRE.INP", "r"))
{
freopen("NRE.INP", "r", stdin);
freopen("NRE.OUT", "w", stdout);
}
faster();
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> b[i];
pre[i] = (b[i] == 0) + pre[i - 1];
}
cin >> q;
while (q--)
{
int l, r; cin >> l >> r;
queries.push_back(Query(l, r));
}
sort(queries.begin(), queries.end());
vector<int> dp(n + 5, oo);
dp[0] = 0;
q = queries.size();
int cur = 0;
for (int i = 1; i <= n; i++)
{
dp[i] = (0 != b[i]) + dp[i - 1];
while (cur < q && queries[cur].l < i) cur++;
if (cur == q || queries[cur].l > i)
continue;
while (cur < q && queries[cur].l == i)
{
int l = queries[cur].l;
int r = queries[cur].r;
cout << l << ' ' << r << '\n';
for (int j = l; j <= r; j++)
dp[j] = min(dp[j], dp[i - 1] + segment(i, j));
cout << i << ' ' << dp[2] << '\n';
cur++;
}
}
cout << dp[n] << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |