이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct BitSet
{
unsigned long long A[32];
unsigned long long h;
BitSet()
{
h = 0;
fill_n(A, 32, 0ull);
}
bool operator<(const BitSet& o)const
{
if (h != o.h)
return h < o.h;
for (int i = 0; i < 32; i++)
{
if (A[i] != o.A[i])
return A[i] < o.A[i];
}
return false;
}
void set(int i)
{
int t = i / 64;
i %= 64;
A[t] |= (1ull << i);
h ^= (1ull << i);
return;
}
void unset(int i)
{
int t = i / 64;
i %= 64;
A[t] &= (~(1ull << i));
h ^= (1ull << i);
return;
}
void andas(BitSet &o)
{
h = 0;
for (int t = 0; t < 32; t++)
{
A[t] &= o.A[t];
h ^= A[t];
}
}
int First(int t)
{
int ret = 64 * t;
for (; t < 32; t++)
{
if (A[t] == 0)
{
ret += 64;
}
else
{
return ret + __builtin_ctzll(A[t]);
}
}
return ret;
}
};
BitSet ok[2000];
map<BitSet, int>M;
int dp(BitSet x, int nuo = 0)
{
int i = x.First(nuo / 64);
if (i >= 2000)
return 0;
int &ans = M[x];
if (ans != 0)
return ans;
x.unset(i);
ans = dp(x, i + 1);
x.andas(ok[i]);
ans = max(ans, 1 + dp(x, i + 1));
return ans;
}
int maximum_deevs(vector<int> y)
{
BitSet deevs;
for (ll i = 0; i < (ll)y.size(); i++)
{
ll k = i + 1;
for (ll j = i + 1; j < (ll)y.size(); j++)
{
if ((y[j] - y[i]) * (k - i) >= (y[k] - y[i]) * (j - i))
k = j;
if (k != j)
ok[i].set(j);
}
deevs.set(i);
}
return dp(deevs);
}/*
int main()
{
cout << maximum_deevs({ 6, 1, 5, 2, 3, 1}) << endl;//3
cout << maximum_deevs({ 0, 1, 2}) << endl;//1
}/**/
컴파일 시 표준 에러 (stderr) 메시지
mountains.cpp:105:2: warning: "/*" within comment [-Wcomment]
}/**/
# | 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... |