E. Nicest view (time limit exceed)
This commit is contained in:
195
src/E. Nicest view.cpp
Normal file
195
src/E. Nicest view.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
// https://codeforces.com/problemset/gymProblem/104945/E
|
||||
|
||||
// #define FAST_EXECUTION
|
||||
// #define INTERACTIVE_MODE
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// https://github.com/coder3101/cf-template/blob/master/template.cc
|
||||
const long long INF = 9223372036854775807;
|
||||
const long long MOD = 1e9 + 7;
|
||||
|
||||
#ifndef ONLINE_JUDGE
|
||||
#define WATCH(key, val)\
|
||||
printf("Watched %s -> %s \n", key, to_string(val).c_str());
|
||||
#define WATCH_CONTAINER(key, val)\
|
||||
printf("Watched %s : ", key);\
|
||||
for (auto e : val)\
|
||||
printf(" %s", to_string(e).c_str());\
|
||||
printf("\n");
|
||||
#define WATCH_MAP(map)\
|
||||
printf("Watching Map\n");\
|
||||
for (auto e : map)\
|
||||
printf("%s -> %s\n", to_string(e.first).c_str(),\
|
||||
to_string(e.second).c_str());\
|
||||
printf("\n");
|
||||
#else
|
||||
#define WATCH(key, val)\
|
||||
do {\
|
||||
} while (false);
|
||||
#define WATCH_CONTAINER(key, val)\
|
||||
do {\
|
||||
} while (false);
|
||||
#define WATCH_MAP(map)\
|
||||
do {\
|
||||
} while (false);
|
||||
#endif
|
||||
|
||||
#ifdef FAST_EXECUTION
|
||||
#pragma GCC optimize("O3")
|
||||
#pragma comment(linker, "/stack:247474112")
|
||||
#endif
|
||||
|
||||
#define REP(n) for(int t=0; t<n; t++)
|
||||
#define FOR(i, n) for (i = 0; i < n; i++)
|
||||
#define FFOR(i, j, n) for(i = j; i < n; i++)
|
||||
#define FOR_S(i, n, k) for (i = 0; i < n; i += k)
|
||||
#define RFOR(i, n) for (i = n - 1; i >= 0; i--)
|
||||
#define RFOR_S(i, n, k) for (i = n - 1; i >= 0; i -= k)
|
||||
#define MAX_OF(x, y) ((x > y) ? x : y)
|
||||
#define MIN_OF(x, y) ((x > y) ? y : x)
|
||||
#define MIN_IN(A) *(min_element(A.begin(), A.end()))
|
||||
#define MAX_IN(A) *(max_element(A.begin(), A.end()))
|
||||
#define MAX_AT(A) (max_element(A.begin(), A.end()) - A.begin())
|
||||
#define MIN_AT(A) (min_element(A.begin(), A.end()) - A.begin())
|
||||
#define TESTCASE\
|
||||
int testcase;\
|
||||
cin>>testcase;\
|
||||
while(testcase--)
|
||||
#define GCD(a,b) __gcd(a,b)
|
||||
#define LCM(a,b) (a)*((b)/__gcd(a,b))
|
||||
#define SORT(A) sort(A.begin(), A.end());
|
||||
#define RSORT(A) sort(A.rbegin(), A.rend());
|
||||
#define REVERSE(A) reverse(A.begin(), A.end());
|
||||
#define ANY(container, result, condition)\
|
||||
result = false;\
|
||||
for (const auto &e : container)\
|
||||
if (condition(e)) {\
|
||||
result = true;\
|
||||
break;\
|
||||
}
|
||||
#define ALL(container, result, condition)\
|
||||
result = true;\
|
||||
for (const auto &e : container)\
|
||||
if (!condition(e)) {\
|
||||
result = false;\
|
||||
break;\
|
||||
}
|
||||
#ifdef INTERACTIVE_MODE
|
||||
#define iprint(...)\
|
||||
printf(__VA_ARGS__);\
|
||||
fflush(stdout);
|
||||
#else
|
||||
#define iprint(...) printf(__VA_ARGS__);
|
||||
#endif
|
||||
|
||||
#define LL long long
|
||||
#define L long
|
||||
#define ULL unsigned long long
|
||||
#define I int
|
||||
#define D double
|
||||
#define UI unsigned int
|
||||
#define VEC(i) vector<i>
|
||||
#define MAP(a, b) map<a, b>
|
||||
#define UMAP(a, b) unordered_map<a, b>
|
||||
#define SET(a) set<a>
|
||||
#define USET(a) unordered_set<a>
|
||||
#define MSET(a) multiset<a>
|
||||
#define STR string
|
||||
#define PAIR(a,b) pair<a,b>
|
||||
#define PAIRI pair<int, int>
|
||||
#define READ_INT(var) scanf("%d", &var);
|
||||
#define READ_STR(var) cin >> var;
|
||||
#define READ_LONG(var) scanf("%lld", &var);
|
||||
#define WRITE_INT(var) printf("%d", var);
|
||||
#define WRITE_LONG(var) printf("%lld", var);
|
||||
#define WRITE_STR(var) cout << var;
|
||||
#define WRITE_VEC_LL(val)\
|
||||
for (auto e : val)\
|
||||
printf("%lld ", e);
|
||||
#define WRITE_VEC_I(val)\
|
||||
for (auto e : val)\
|
||||
printf("%d ", e);
|
||||
|
||||
#define pb push_back
|
||||
#define eb emplace_back
|
||||
|
||||
LL power(LL x, ULL y) {
|
||||
LL res = 1;
|
||||
x = x % MOD;
|
||||
while (y > 0) {
|
||||
if (y & 1)
|
||||
res = (res*x) % MOD;
|
||||
y = y>>1;
|
||||
x = (x*x) % MOD;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
const int N = 1e9;
|
||||
|
||||
int main() {
|
||||
UI n;
|
||||
READ_INT(n)
|
||||
VEC(UI) hikes(n);
|
||||
UI i;
|
||||
FOR(i, n) {
|
||||
READ_INT(hikes[i])
|
||||
}
|
||||
class Score {
|
||||
public:
|
||||
UI numerator = 0;
|
||||
UI denominator = 1;
|
||||
D getValue() const { return (D)numerator / denominator; };
|
||||
void print() const {
|
||||
if (numerator % denominator) {
|
||||
printf("%d/%d", numerator, denominator);
|
||||
} else {
|
||||
printf("%d", (I)getValue());
|
||||
}
|
||||
}
|
||||
};
|
||||
Score best_score;
|
||||
I j;
|
||||
FOR(i, n) {
|
||||
Score current_score;
|
||||
RFOR(j, i) {
|
||||
if (hikes[j] >= hikes[i]) {
|
||||
current_score.numerator = hikes[i] - hikes[j + 1];
|
||||
current_score.denominator = hikes[j] - hikes[j + 1];
|
||||
current_score.numerator += (i - j - 1) * current_score.denominator;
|
||||
if (current_score.getValue() > best_score.getValue()) {
|
||||
best_score = current_score;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
FFOR(j, i + 1, n) {
|
||||
if (hikes[j] >= hikes[i]) {
|
||||
current_score.numerator = hikes[i] - hikes[j - 1];
|
||||
current_score.denominator = hikes[j] - hikes[j - 1];
|
||||
current_score.numerator += (j - i - 1) * current_score.denominator;
|
||||
if (current_score.getValue() > best_score.getValue()) {
|
||||
best_score = current_score;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
best_score.print();
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user