Submission #370847

# Submission time Handle Problem Language Result Execution time Memory
370847 2021-02-24T18:49:53 Z Traduttore Exam (eJOI20_exam) C++14
26 / 100
1000 ms 3564 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define int ll
#define pll pair <ll,ll>
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define TIME 1.0*clock()/CLOCKS_PER_SEC
using namespace std;
using namespace __gnu_pbds;
mt19937_64 gen(time(0));
int n,q;
vector <int> a;
vector <int> b;
void init() {
    cin>>n;
    a.resize(n);
    for (int i = 0;i < n;i++)
        cin>>a[i];
    b.resize(n);
    for (int i = 0;i < n;i++)
        cin>>b[i];
}
ll ans = 0;
void output() {
    cout<<ans<<'\n';
}
void solve() {
    bool can = true;
    int pos = -1;
    int kol = 0;
    for (int i = 0;i < n;i++)
    {
    	if (a[i] > b[i]) {
    		if (can != true) ans+=kol;
    		can = true;
    		kol = 0;
    	}
    	else if (a[i] == b[i]) {++kol;can = false;}
    	else ++kol;
    }
    if (can != true) ans+=kol;
}
vector <int> dp((int)(1e5) ^ 1);
vector <int> dp3((int)(1e5) ^ 1);
void solve2() {
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
for (int i = 0;i < n;i++)
{
    int oz = dp[i];
    int mx = 0;
    vector <int> dp2;
    dp2 = dp;
    for (int j = i;j < n;j++)
    {
    int kol = 0;
    	for (int q = j;q < n;q++)
    	{
    		if (a[q] > a[i]) continue;
    		if (a[i] == b[q]) ++kol;
    		dp2[q + 1] = max(dp2[q + 1],dp[j] + kol);
    	}
    }
    dp = dp2;
}
ans = dp[n];
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
for (int i = 0;i < n;i++)
{
    int oz = dp3[i];
    int mx = 0;
    vector <int> dp2;
    dp2 = dp3;
    for (int j = i;j < n;j++)
    {
    int kol = 0;
    	for (int q = j;q < n;q++)
    	{
    		if (a[q] > a[i]) continue;
    		if (a[i] == b[q]) ++kol;
    		dp2[q + 1] = max(dp2[q + 1],dp3[j] + kol);
    	}
    }
    dp3 = dp2;
}
ans = max(dp3[n],ans);
}
int32_t main() {
    srand(time(0));
  //freopen("input.txt","r",stdin);
 // freopen("output.txt","w",stdout);
IOS;
int test;
test = 1;
while (test--) {
    init();
    bool has = true;
    for (int i = 0;i < n - 1;i++)
    if (b[i] != b[i + 1]) {
        has = false;
        break;
    }
    if (has == true) solve();
    else solve2();
    output();
}
exit(0);}
/*3 5 7 9 10 11*/
/*5 14 13 8 14 11*/

Compilation message

exam.cpp: In function 'void solve()':
exam.cpp:34:9: warning: unused variable 'pos' [-Wunused-variable]
   34 |     int pos = -1;
      |         ^~~
exam.cpp: In function 'void solve2()':
exam.cpp:55:9: warning: unused variable 'oz' [-Wunused-variable]
   55 |     int oz = dp[i];
      |         ^~
exam.cpp:56:9: warning: unused variable 'mx' [-Wunused-variable]
   56 |     int mx = 0;
      |         ^~
exam.cpp:76:9: warning: unused variable 'oz' [-Wunused-variable]
   76 |     int oz = dp3[i];
      |         ^~
exam.cpp:77:9: warning: unused variable 'mx' [-Wunused-variable]
   77 |     int mx = 0;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 4 ms 2668 KB Output is correct
5 Correct 4 ms 2668 KB Output is correct
6 Correct 4 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 9 ms 2284 KB Output is correct
3 Correct 17 ms 3308 KB Output is correct
4 Correct 16 ms 3564 KB Output is correct
5 Correct 26 ms 3436 KB Output is correct
6 Correct 15 ms 3564 KB Output is correct
7 Correct 15 ms 3436 KB Output is correct
8 Correct 25 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 179 ms 2668 KB Output is correct
3 Execution timed out 1084 ms 2796 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 2944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 4 ms 2668 KB Output is correct
5 Correct 4 ms 2668 KB Output is correct
6 Correct 4 ms 2668 KB Output is correct
7 Incorrect 4 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 4 ms 2668 KB Output is correct
5 Correct 4 ms 2668 KB Output is correct
6 Correct 4 ms 2668 KB Output is correct
7 Correct 4 ms 2668 KB Output is correct
8 Correct 179 ms 2668 KB Output is correct
9 Execution timed out 1084 ms 2796 KB Time limit exceeded
10 Halted 0 ms 0 KB -