제출 #1295246

#제출 시각아이디문제언어결과실행 시간메모리
1295246luattapcodePotatoes and fertilizers (LMIO19_bulves)C++20
100 / 100
158 ms8596 KiB
/*The best way to get something done is to begin*/ #include <bits/stdc++.h> #define ll long long #define int long long #define fr(i,a,b) for(int i=a;i<=b;i++) #define frd(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define fi first #define se second #define el '\n' using namespace std; template <class X, class Y> bool minimize(X &x, const Y &y) {if (x > y) {x = y;return true;} else return false;} template <class X, class Y> bool maximize(X &x, const Y &y) {if (x < y) {x = y;return true;} else return false;} /* Author: Huynh Quoc Luat */ /*Khai Bao*/ const long long inf=1e18; const int oo=1e9; const int LO=21; const int CH=27; const int sm=1e9+7; //void add(int &x,const int &y){x+=y;if(x>=sm)x-=sm;} //void sub(int &x,const int &y){x-=y;if(x<0)x+=sm;} const int N = 5e5 + 5; int d[N]; int n; void read() { cin >> n; fr(i,1,n){ int x,y; cin >> x >> y; d[i] = d[i-1] + x - y; } } namespace sub1 { const int N = 3005; int dp[N][N]; void process() { memset(dp,0x3f,sizeof dp); dp[0][0] = 0; fr(i,1,n){ fr(j,0,d[n]){ fr(k,0,j){ minimize(dp[i][j],dp[i-1][k] + abs(j - d[i])); } } } cout << dp[n][d[n]]; } } namespace sub2 { struct cmp{ bool operator()(int u,int v){ return u < v; } }; priority_queue <int,vector <int>,cmp> h; int res = 0; void process(){ fr(i,1,n-1){ if(d[i] < 0) res -= d[i], d[i] = 0; res += d[i]; h.push(d[i]); h.push(d[i]); h.pop(); } while(!h.empty()){ int x = h.top(); h.pop(); res -= min(x,d[n]); } cout << res; } } void time() {cerr<< endl<<"Luattapcode: "<<clock()<<"ms"<<endl;} main() { ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL); #define TASK "qn" if(fopen(TASK".INP","r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } int mtt=0; int test=1; if(mtt) cin>>test; while(test--) { read(); sub2::process(); } time(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

bulves.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   84 | main()
      | ^~~~
bulves.cpp: In function 'int main()':
bulves.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...