Submission #225707

#TimeUsernameProblemLanguageResultExecution timeMemory
225707Ruxandra985Rope (JOI17_rope)C++14
45 / 100
2587 ms2688 KiB
#include <bits/stdc++.h> using namespace std; int v[1000010] , dp[1000010][2][2] , sol[1000010]; int main() { FILE *fin = stdin; FILE *fout = stdout; int n , m , i , j , k , difj , difk , x; fscanf (fin,"%d%d",&n,&m); for (i = 1 ; i <= n ; i++){ fscanf (fin,"%d",&v[i]); } for (i = 1 ; i <= m ; i++) sol[i] = 2000000000 * (m != 1); for (j = 1 ; j <= m ; j++){ for (k = 1 ; k <= m ; k++){ if (j == k) continue; /// pui culoarea j sau k peste tot /// forma generala : /// orice , par , par , ... , par , orice /// dp[i][tip_cul][0 / 1] = cmin pana la i, ai culoarea aia, len % 2 = 0 / 1 dp[1][0][1] = (v[1] != j); dp[1][1][1] = (v[1] != k); dp[1][0][0] = dp[1][1][0] = 2000000000; difj = (v[1] != j); difk = (v[1] != k); for (i = 2 ; i <= n ; i++){ dp[i][0][1] = min( dp[i - 1][0][0] , min( difk , dp[i - 1][1][0] ) ) + (v[i] != j); dp[i][1][1] = min( dp[i - 1][1][0] , min( difj , dp[i - 1][0][0] ) ) + (v[i] != k); dp[i][0][0] = dp[i - 1][0][1] + (v[i] != j); dp[i][1][0] = dp[i - 1][1][1] + (v[i] != k); difj += (v[i] != j); difk += (v[i] != k); } x = min( min( dp[n][0][1] , dp[n][1][1] ) , min( dp[n][0][0] , dp[n][1][0] ) ); sol[j] = min(sol[j] , x); sol[k] = min(sol[k] , x); } } for (i = 1 ; i <= m ; i++) fprintf (fout,"%d\n",sol[i]); return 0; }

Compilation message (stderr)

rope.cpp: In function 'int main()':
rope.cpp:10:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
rope.cpp:12:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&v[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~
#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...