QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#77173#5500. BarsUCSC_Ravioli#WA 258ms3532kbC++201.4kb2023-02-13 07:35:452023-02-13 07:35:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-13 07:35:49]
  • 评测
  • 测评结果:WA
  • 用时:258ms
  • 内存:3532kb
  • [2023-02-13 07:35:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<ll> v(n);
		for(auto &d:v) cin >> d;
		vector<int> st{0};
		// Optimal solution assuming bars 0 and i are the leftmost and rightmost bars
		for(int i=1; i<n; i++){
			while(st.size() >= 2){
				ll keep = v[end(st)[-1]] * (i - end(st)[-2]);
				keep += v[end(st)[-2]] * (end(st)[-1] - end(st)[-2]);
				keep += v[i] * (i - end(st)[-1]);
				
				ll rmv = v[end(st)[-2]] * (i - end(st)[-2]);
				rmv += v[i] * (i - end(st)[-2]);
				
				// cout << "at bar " << i << endl;
				// cout << "stack: ";
				// for(int d:st) cout << d << ' ';
				// cout << endl;
				// cout << "keep: " << keep << endl;
				// cout << "rmv: " << rmv << endl;
				
				if(rmv >= keep) st.pop_back();
				break;
			}
			ll addme = v[i] * (n - 1 - end(st)[-1]);
			addme += v[end(st)[-1]] * (i - end(st)[-1]);
			ll dontaddme = v[end(st)[-1]] * (n - 1 - end(st)[-1]);
			if(addme > dontaddme) st.push_back(i);
		}
		int m = st.size();
		
		// cout << "stack: ";
		// for(int d:st) cout << d << ' ';
		// cout << endl;
		
		ll ans = v[st[0]] * (st[1] - st[0]);
		ans += v[end(st)[-1]] * (end(st)[-1] - end(st)[-2]);
		for(int i=1; i+1<m; i++){
			ans += v[st[i]] * (st[i+1] - st[i-1]);
		}
		cout << ans << endl;
	}
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3336kb

input:

2
4
5 2 2 6
5
1 5 4 4 1

output:

33
29

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 258ms
memory: 3532kb

input:

10000
4
5 2 2 6
5
1 5 4 4 1
197
763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...

output:

33
29
374491659372
647156842826
536636053639
458946673513
296420749955
853032075523
619529562601
574204146040
225238173573
700311050238
450602174920
275424570658
585094154153
195545309788
336548826266
469142128115
590694831816
575346200779
398858274722
817342192610
954362974321
900878825791
26408806...

result:

wrong answer 3rd lines differ - expected: '382465638565', found: '374491659372'