Submission #855469

#TimeUsernameProblemLanguageResultExecution timeMemory
855469devesh_7Bigger segments (IZhO19_segments)C++14
0 / 100
1 ms500 KiB
#include<bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // Including tree_order_statistics_node_update // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define MOD1 998244353 #define INF 1e18 #define nline "\n" #define pb push_back #define ppb pop_back #define mp make_pair #define ff first #define ss second #define PI 3.141592653589793238462 #define set_bits __builtin_popcountll #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef long double lld; // typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(lld t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} ll mod=1e9+7; ll power(ll a,ll b){ ll temp=a; ll num=1; while(b>0){ if(b%2==1){ num*=temp; num%=mod; } temp*=temp; temp%=mod; b/=2; } return num; } ll modulo_inv(ll a){ return power(a,mod-2); } ll ncr(ll n,ll r,ll fact[],ll inv_fact[]){ if(n<r){ return 0; } return (((fact[n]*inv_fact[r])%mod)*inv_fact[n-r])%mod; } ll gcd(ll a,ll b){ if(b==0){ return a; } return gcd(b,a%b); } bool isPowerOfTwo(ll x) { if(x<0) return false; /* First x in the below expression is for the case when * x is 0 */ return x && (!(x & (x - 1))); } int main() { #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif fastio(); ll n; cin>>n; ll a[n+1]; a[0]=0; for(int i=1;i<=n;i++){ cin>>a[i]; a[i]+=a[i-1]; } set<pair<ll,ll>>st; st.insert({0,0}); vector<pair<ll,ll>>dp(n+1,{1e15,1}); dp[0]={0,0}; for(int i=1;i<=n;i++){ auto itr=st.upper_bound({a[i],LLONG_MAX}); itr--; dp[i].first=a[i]-a[itr->second]; dp[i].second=dp[itr->second].second+1; st.insert({a[i]+dp[i].first,i}); } cout<<dp[n].second; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:95:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     freopen("Error.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...