Submission #783135

#TimeUsernameProblemLanguageResultExecution timeMemory
783135peraXor Sort (eJOI20_xorsort)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 1; main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); int n , oK = 1;cin >> n; vector<int> a(n + 1) , b(n + 1); for(int i = 1;i <= n;i ++){ cin >> a[i]; } for(int i = 1;i <= n;i ++){ cin >> b[i]; if(i != 1) oK &= (b[i] == b[i - 1]); } if(oK){ int c = 0 , C = 0 , ok = 0; for(int i = 1;i <= n;i ++){ if(a[i] > b[i]){ if(ok) c += C; C = 0; continue; } if(a[i] == b[i]) ok = 1; ++ C; } if(ok) c += C; cout << c << endl; }else{ oK = 1; for(int i = 2;i <= n;i ++){ oK &= (a[i] > a[i - 1]); } if(oK){ vector<int> dp(n + 1); vector<vector<int>> c(n + 1 , vector<int>(n + 1)); for(int i = 1;i <= n;i ++){ for(int j = 1;j <= n;j ++){ c[i][j] = c[i][j - 1] + (b[j] == a[i]); } } dp[1] = (a[1] == b[1]); for(int i = 2;i <= n;i ++){ for(int j = 1;j < i;j ++){ dp[i] = max(dp[i] , dp[j] + c[i][i] - c[i][j - 1]); } } cout << dp[n] << endl; } } }

Compilation message (stderr)

xorsort.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...