Submission #402657

#TimeUsernameProblemLanguageResultExecution timeMemory
402657Ruxandra985Bigger segments (IZhO19_segments)C++14
100 / 100
126 ms14948 KiB
#include <bits/stdc++.h> #define DIMN 500010 using namespace std; pair <int, int> dp[DIMN]; int v[DIMN]; long long sp[DIMN]; int main() { FILE *fin = stdin; FILE *fout = stdout; int n , i , st , dr , mid; fscanf (fin,"%d",&n); for (i = 1 ; i <= n ; i++){ fscanf (fin,"%d",&v[i]); sp[i] = v[i] + sp[i - 1]; dp[i] = make_pair(1 , 1);/// o secventa, incepe la 1 si se termina la i } for (i = 1 ; i <= n ; i++){ if (i > 1){ /// 1. iei o sg secventa de la 1 la i, initializat /// 2. prelungesti cu 1 secventa de la i - 1 if (dp[i].first < dp[i - 1].first || (dp[i].first == dp[i - 1].first && dp[i].second < dp[i - 1].second)){ dp[i].first = dp[i - 1].first; dp[i].second = dp[i - 1].second; } } /// acuma ma duc in unele mai mari st = i + 1; dr = n; while (st <= dr){ mid = (st + dr)/2; if (sp[mid] - sp[i] >= sp[i] - sp[dp[i].second - 1]) /// e ok dr = mid - 1; else st = mid + 1; } /// solutia in st if (dp[st].first < dp[i].first + 1 || (dp[st].first == dp[i].first + 1 && i + 1 > dp[st].second)){ dp[st].first = dp[i].first + 1; dp[st].second = i + 1; } } fprintf (fout,"%d",dp[n].first); return 0; }

Compilation message (stderr)

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