Submission #447807

#TimeUsernameProblemLanguageResultExecution timeMemory
447807cpp219Group Photo (JOI21_ho_t3)C++14
100 / 100
286 ms67400 KiB
#pragma GCC optimization O2 #pragma GCC optimization "unroll-loop" #pragma target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 5e3 + 9; const ll Log2 = 21; const ll inf = 1e9 + 7; ll n,a[N],pos[N],inv[N][N],dp[N]; int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n; for (ll i = 1;i <= n;i++) cin>>a[i],pos[a[i]] = i; for (ll j = 2;j <= n;j++){ ll now = 0; for (ll i = j - 1;i;i--){ now += (pos[i] > pos[j]); inv[i][j] = inv[i][j - 1] + now; } } for (ll i = 1;i <= n;i++){ dp[i] = inf; for (ll j = i - 1;j >= 0;j--) dp[i] = min(dp[i], dp[j] + inv[1][i] - inv[1][j] + ((i - j)*(i - j - 1))/2 - 2 * inv[j + 1][i]); } cout<<dp[n]; }

Compilation message (stderr)

Main.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
Main.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
Main.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
Main.cpp: In function 'int main()':
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...