# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
660564 | 600Mihnea | 사다리꼴 (balkan11_trapezoid) | C++17 | 133 ms | 13024 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
bool home = 0;
#include <bits/stdc++.h>
using namespace std;
const int MODULO = 30013;
struct T
{
int a;
int b;
int c;
int d;
};
bool operator < (T first, T second)
{
return first.a < second.a;
}
struct P
{
int dp;
int cnt;
};
P operator + (P a, P b)
{
if (a.dp > b.dp)
{
return a;
}
if (a.dp < b.dp)
{
return b;
}
return {a.dp, (a.cnt + b.cnt) % MODULO};
}
int main()
{
if (home == 0)
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
else
{
freopen ("input.txt", "r", stdin);
}
int n;
cin >> n;
vector<T> v(n);
map<int, int> mp;
for (auto &it : v)
{
cin >> it.a >> it.b >> it.c >> it.d;
it.c--;
mp[it.c] = 0;
mp[it.d] = 0;
}
int yahor = 0;
for (auto &it : mp)
{
it.second = ++yahor;
}
for (auto &it : v)
{
it.c = mp[it.c];
it.d = mp[it.d];
}
sort(v.begin(), v.end());
vector<P> fw(yahor + 1);
vector<int> iB(n);
iota(iB.begin(), iB.end(), 0);
sort(iB.begin(), iB.end(), [&] (int i, int j) {
return v[i].b < v[j].b;
});
int ptr = 0;
vector<int> dp(n, 0), ways(n, 0);
for (int i = 0; i < n; i++)
{
while (ptr < n && v[iB[ptr]].b < v[i].a)
{
for (int x = v[iB[ptr]].d; x <= yahor; x += x & (-x))
{
fw[x] = fw[x] + P{dp[iB[ptr]] + 1, ways[iB[ptr]]};
}
ptr++;
}
P sol = {1, 1};
for (int x = v[i].c; x; x -= x & (-x))
{
sol = sol + fw[x];
}
dp[i] = sol.dp;
ways[i] = sol.cnt;
}
int mx = *max_element(dp.begin(), dp.end()), cnt = 0;
for (int i = 0; i < n; i++)
{
if (dp[i] == mx)
{
cnt = (cnt + ways[i]) % MODULO;
}
}
cout << mx << " " << cnt << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |