# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
462357 |
2021-08-10T12:00:14 Z |
idas |
Exam (eJOI20_exam) |
C++11 |
|
1000 ms |
91356 KB |
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()
const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;
void setIO()
{
FAST_IO;
}
void setIO (string s)
{
setIO();
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const int N=5e3+10;
int n, a[N], b[N], t[2*N];
ll dp[N][N];
void build()
{
for(int i=n-1; i>=0; i--) t[i]=max(t[i<<1], t[i<<1|1]);
}
int get(int l, int r)
{
int ret=0;
for(l+=n, r+=n; l<r; l>>=1, r>>=1){
if(l&1) ret=max(ret, t[l++]);
if(r&1) ret=max(ret, t[--r]);
}
return ret;
}
int main()
{
setIO();
cin >> n;
FOR(i, 0, n)
{
cin >> a[i];
t[i+n]=a[i];
}
FOR(i, 0, n) cin >> b[i];
build();
FOR(i, 0, n)
{
int mx=get(0, i+1);
if(b[0]==mx){
dp[0][i]=max(dp[0][i], 1LL);
}
}
ll ans=0;
FOR(i, 1, n)
{
FOR(j, 0, n)
{
if(i+j+1>N) continue;
ll mx1=get(i-1, i+j+1), mx2=get(i, i+j+1);
ll val=max(dp[i-1][j+1]+(mx1==b[i]?1LL:0LL), dp[i-1][0]+(mx2==b[i]?1LL:0LL));
dp[i][j]=max(dp[i][j], val);
}
}
FOR(i, 0, n)
{
FOR(j, 0, n)
{
ans=max(ans, dp[i][j]);
// cout << dp[i][j] << " ";
}
//cout << '\n';
}
cout << ans;
}
Compilation message
exam.cpp: In function 'void setIO(std::string)':
exam.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exam.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
272 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
107 ms |
12216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1101 ms |
91356 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
272 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
272 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |