제출 #861938

#제출 시각아이디문제언어결과실행 시간메모리
861938guagua0407Two Dishes (JOI19_dishes)C++17
컴파일 에러
0 ms0 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=1e6+5; ll a[mxn],S[mxn],Q[mxn]; ll b[mxn],T[mxn],P[mxn]; int pa[mxn],pb[mxn]; ll g[mxn],V[mxn]; vector<int> qa[mxn],qb[mxn]; int n,m; int main() {_ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]>>S[i]>>P[i]; a[i]+=a[i-1]; } for(int i=1;i<=m;i++){ cin>>b[i]>>T[i]>>Q[i]; b[i]+=b[i-1]; } for(int i=1;i<=n;i++){ int pos=upper_bound(b,b+m+1,S[i]-a[i])-b-1; pa[i]=pos; if(pos>=0) qa[pos].push_back(i); } for(int i=1;i<=m;i++){ int pos=upper_bound(a,a+n+1,T[i]-b[i])-a-1; pb[i]=pos; if(pos>=0) qb[pos].push_back(i); } for(int i=1;i<=m;i++){ if(pb[i]>=0) g[i]=V[i]=Q[i]; } for(auto v:qb[0]){ if(g[v]<0){ g[v+1]=max(g[v+1]+g[v],V[v+1]); g[v]=0; } V[v]=0; } for(int i=1;i<=n;i++){ if(pa[i]>=0){ g[0]+=P[i]; g[pa[i]+1]-=P[i]; if(g[pa[i]+1]<V[pa[i]+1]){ g[pa[i]+2]=max(g[pa[i]+2]+g[pa[i]+1],V[pa[i]+2]); g[pa[i]+1]=V[pa[i]+1]; } } for(auto v:qb[i]){ if(g[v]<0){ g[v+1]=max(g[v+1]+g[v],V[v+1]); g[v]=0; } V[v]=0; } } for(int i=1;i<=m;i++){ g[i]+=g[i-1]; } cout<<g[m]<<'\n'; return 0; } //maybe its multiset not set //#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=1e6+5; ll a[mxn],S[mxn],Q[mxn]; ll b[mxn],T[mxn],P[mxn]; int pa[mxn],pb[mxn]; ll g[mxn],V[mxn]; vector<int> qa[mxn],qb[mxn]; int n,m; int main() {_ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]>>S[i]>>P[i]; a[i]+=a[i-1]; } for(int i=1;i<=m;i++){ cin>>b[i]>>T[i]>>Q[i]; b[i]+=b[i-1]; } for(int i=1;i<=n;i++){ int pos=upper_bound(b,b+m+1,S[i]-a[i])-b-1; pa[i]=pos; if(pos>=0) qa[pos].push_back(i); } for(int i=1;i<=m;i++){ int pos=upper_bound(a,a+n+1,T[i]-b[i])-a-1; pb[i]=pos; if(pos>=0) qb[pos].push_back(i); } for(int i=1;i<=m;i++){ if(pb[i]>=0) g[i]=V[i]=Q[i]; } for(auto v:qb[0]){ if(g[v]<0){ g[v+1]=max(g[v+1]+g[v],V[v+1]); g[v]=0; } V[v]=0; } for(int i=1;i<=n;i++){ if(pa[i]>=0){ g[0]+=P[i]; g[pa[i]+1]-=P[i]; if(g[pa[i]+1]<V[pa[i]+1]){ g[pa[i]+2]=max(g[pa[i]+2]+g[pa[i]+1],V[pa[i]+2]); g[pa[i]+1]=V[pa[i]+1]; } } for(auto v:qb[i]){ if(g[v]<0){ g[v+1]=max(g[v+1]+g[v],V[v+1]); g[v]=0; } V[v]=0; } } for(int i=1;i<=m;i++){ g[i]+=g[i-1]; } cout<<g[m]<<'\n'; return 0; } //maybe its multiset not set

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

dishes.cpp:89:6: error: redefinition of 'void setIO(std::string)'
   89 | void setIO(string s) {
      |      ^~~~~
dishes.cpp:11:6: note: 'void setIO(std::string)' previously defined here
   11 | void setIO(string s) {
      |      ^~~~~
dishes.cpp:94:11: error: redefinition of 'const int mxn'
   94 | const int mxn=1e6+5;
      |           ^~~
dishes.cpp:16:11: note: 'const int mxn' previously defined here
   16 | const int mxn=1e6+5;
      |           ^~~
dishes.cpp:95:4: error: redefinition of 'long long int a [1000005]'
   95 | ll a[mxn],S[mxn],Q[mxn];
      |    ^
dishes.cpp:17:4: note: 'long long int a [1000005]' previously declared here
   17 | ll a[mxn],S[mxn],Q[mxn];
      |    ^
dishes.cpp:95:11: error: redefinition of 'long long int S [1000005]'
   95 | ll a[mxn],S[mxn],Q[mxn];
      |           ^
dishes.cpp:17:11: note: 'long long int S [1000005]' previously declared here
   17 | ll a[mxn],S[mxn],Q[mxn];
      |           ^
dishes.cpp:95:18: error: redefinition of 'long long int Q [1000005]'
   95 | ll a[mxn],S[mxn],Q[mxn];
      |                  ^
dishes.cpp:17:18: note: 'long long int Q [1000005]' previously declared here
   17 | ll a[mxn],S[mxn],Q[mxn];
      |                  ^
dishes.cpp:96:4: error: redefinition of 'long long int b [1000005]'
   96 | ll b[mxn],T[mxn],P[mxn];
      |    ^
dishes.cpp:18:4: note: 'long long int b [1000005]' previously declared here
   18 | ll b[mxn],T[mxn],P[mxn];
      |    ^
dishes.cpp:96:11: error: redefinition of 'long long int T [1000005]'
   96 | ll b[mxn],T[mxn],P[mxn];
      |           ^
dishes.cpp:18:11: note: 'long long int T [1000005]' previously declared here
   18 | ll b[mxn],T[mxn],P[mxn];
      |           ^
dishes.cpp:96:18: error: redefinition of 'long long int P [1000005]'
   96 | ll b[mxn],T[mxn],P[mxn];
      |                  ^
dishes.cpp:18:18: note: 'long long int P [1000005]' previously declared here
   18 | ll b[mxn],T[mxn],P[mxn];
      |                  ^
dishes.cpp:97:5: error: redefinition of 'int pa [1000005]'
   97 | int pa[mxn],pb[mxn];
      |     ^~
dishes.cpp:19:5: note: 'int pa [1000005]' previously declared here
   19 | int pa[mxn],pb[mxn];
      |     ^~
dishes.cpp:97:13: error: redefinition of 'int pb [1000005]'
   97 | int pa[mxn],pb[mxn];
      |             ^~
dishes.cpp:19:13: note: 'int pb [1000005]' previously declared here
   19 | int pa[mxn],pb[mxn];
      |             ^~
dishes.cpp:98:4: error: redefinition of 'long long int g [1000005]'
   98 | ll g[mxn],V[mxn];
      |    ^
dishes.cpp:20:4: note: 'long long int g [1000005]' previously declared here
   20 | ll g[mxn],V[mxn];
      |    ^
dishes.cpp:98:11: error: redefinition of 'long long int V [1000005]'
   98 | ll g[mxn],V[mxn];
      |           ^
dishes.cpp:20:11: note: 'long long int V [1000005]' previously declared here
   20 | ll g[mxn],V[mxn];
      |           ^
dishes.cpp:99:13: error: redefinition of 'std::vector<int> qa [1000005]'
   99 | vector<int> qa[mxn],qb[mxn];
      |             ^~
dishes.cpp:21:13: note: 'std::vector<int> qa [1000005]' previously declared here
   21 | vector<int> qa[mxn],qb[mxn];
      |             ^~
dishes.cpp:99:21: error: redefinition of 'std::vector<int> qb [1000005]'
   99 | vector<int> qa[mxn],qb[mxn];
      |                     ^~
dishes.cpp:21:21: note: 'std::vector<int> qb [1000005]' previously declared here
   21 | vector<int> qa[mxn],qb[mxn];
      |                     ^~
dishes.cpp:100:5: error: redefinition of 'int n'
  100 | int n,m;
      |     ^
dishes.cpp:22:5: note: 'int n' previously declared here
   22 | int n,m;
      |     ^
dishes.cpp:100:7: error: redefinition of 'int m'
  100 | int n,m;
      |       ^
dishes.cpp:22:7: note: 'int m' previously declared here
   22 | int n,m;
      |       ^
dishes.cpp:102:5: error: redefinition of 'int main()'
  102 | int main() {_
      |     ^~~~
dishes.cpp:24:5: note: 'int main()' previously defined here
   24 | int main() {_
      |     ^~~~
dishes.cpp: In function 'void setIO(std::string)':
dishes.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp: In function 'void setIO(std::string)':
dishes.cpp:90:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:91:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~