Submission #1286760

#TimeUsernameProblemLanguageResultExecution timeMemory
1286760SmuggingSpunBitaro's travel (JOI23_travel)C++20
15 / 100
15 ms1152 KiB
#include<bits/stdc++.h>
#define taskname "C"
using namespace std; 
typedef long long ll;
const int lim = 2e5 + 5;
int n, q, a[lim];
namespace sub12{
	void solve(){
		int s, p;
		cin >> s;
		ll ans = 0;
		for(int r = upper_bound(a + 1, a + n + 1, s) - a, l = r - 1, _ = 0; _ < n; _++){
			if(l == 0 || (r != n + 1 && s - a[l] > a[r] - s)){
				ans += a[r] - s;
				s = a[r++];
			}			
			else{
				ans += s - a[l];
				s = a[l--];
			}
		}
		cout << ans;
	}
}
namespace sub34{
	void solve(){
		
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	cin >> q;
	if(q == 1){
		sub12::solve();
	}
	else{
		sub34::solve();
	}
}

Compilation message (stderr)

travel.cpp: In function 'int main()':
travel.cpp:33:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...