답안 #833134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833134 2023-08-22T02:04:38 Z josanneo22 Feast (NOI19_feast) C++17
22 / 100
28 ms 8024 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define ar array
long long maxSubArraySum(vector<long long> a, int size)
{
	long long max_so_far = LLONG_MIN, max_ending_here = 0;
	int starting_index = 0, ending_index = 0, s = 0;
	for (int i = 0; i < size; i++) {
		max_ending_here = max_ending_here + a[i];
		if (max_so_far < max_ending_here) {
			max_so_far = max_ending_here; starting_index = s; ending_index = i;
		}

		if (max_ending_here < 0) {
			max_ending_here = 0;
			s = i + 1;
		}
	}
	return max_so_far;
}
void solve(){
	int n,k; cin>>n>>k;
	vector<int> a(n); for(int i=0;i<n;i++) cin>>a[i];
	cout<<max(0LL,maxSubArraySum(a,n))<<'\n';
}
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	clock_t tStart = clock();
	int local=0,multi=0,debug=1,tt=1;
	if(local){
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	}	
	if(multi) cin>>tt;
	for(int i=1;i<=tt;i++){
		if(debug && multi && local) cout<<"样例 "<<i<<'\n';
		solve();
 	}
	fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}

Compilation message

feast.cpp: In function 'long long int maxSubArraySum(std::vector<long long int>, long long int)':
feast.cpp:15:6: warning: variable 'starting_index' set but not used [-Wunused-but-set-variable]
   15 |  int starting_index = 0, ending_index = 0, s = 0;
      |      ^~~~~~~~~~~~~~
feast.cpp:15:26: warning: variable 'ending_index' set but not used [-Wunused-but-set-variable]
   15 |  int starting_index = 0, ending_index = 0, s = 0;
      |                          ^~~~~~~~~~~~
feast.cpp: In function 'int main()':
feast.cpp:39:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |      freopen("input.txt","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:40:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |      freopen("output.txt","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 4820 KB Output is correct
2 Correct 23 ms 4948 KB Output is correct
3 Correct 25 ms 4984 KB Output is correct
4 Correct 23 ms 4948 KB Output is correct
5 Correct 24 ms 4812 KB Output is correct
6 Correct 23 ms 4820 KB Output is correct
7 Correct 24 ms 4784 KB Output is correct
8 Correct 24 ms 4948 KB Output is correct
9 Correct 24 ms 4780 KB Output is correct
10 Correct 24 ms 4820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 4820 KB Output is correct
2 Correct 16 ms 6108 KB Output is correct
3 Correct 16 ms 5972 KB Output is correct
4 Incorrect 16 ms 5972 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 4948 KB Output is correct
2 Correct 26 ms 7892 KB Output is correct
3 Correct 27 ms 7888 KB Output is correct
4 Correct 26 ms 7756 KB Output is correct
5 Correct 27 ms 7884 KB Output is correct
6 Correct 27 ms 8020 KB Output is correct
7 Correct 27 ms 8012 KB Output is correct
8 Correct 26 ms 7872 KB Output is correct
9 Correct 27 ms 8012 KB Output is correct
10 Correct 28 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 224 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 224 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 224 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 4820 KB Output is correct
2 Correct 23 ms 4948 KB Output is correct
3 Correct 25 ms 4984 KB Output is correct
4 Correct 23 ms 4948 KB Output is correct
5 Correct 24 ms 4812 KB Output is correct
6 Correct 23 ms 4820 KB Output is correct
7 Correct 24 ms 4784 KB Output is correct
8 Correct 24 ms 4948 KB Output is correct
9 Correct 24 ms 4780 KB Output is correct
10 Correct 24 ms 4820 KB Output is correct
11 Correct 15 ms 4820 KB Output is correct
12 Correct 16 ms 6108 KB Output is correct
13 Correct 16 ms 5972 KB Output is correct
14 Incorrect 16 ms 5972 KB Output isn't correct
15 Halted 0 ms 0 KB -