답안 #470670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470670 2021-09-04T20:56:34 Z Bungmint Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
240 ms 15232 KB
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpi = vector<pii>;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
using ld = long double;

#define all(v) (v).begin(), (v).end()
#define ar array
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define REP(a) F0R(_, a)

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353;
const ld PI = acos((ld)-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <typename T>
bool ckmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
    os << '{';
    string sep;
    for (const T &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}
void dbg_out()
{
    cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

struct chash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(pair<uint64_t,uint64_t> x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);
	}
};

void setIO(string s)
{
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

ll fst =0;
priority_queue<ll> pq;

void solve()
{
	int n;
	cin >> n;
	vl dif(n+1);
	FOR(i,1,1+ n){
		int a, b;
		cin>> a >> b;
		dif[i] = dif[i-1] + a-b;
	}
	FOR(i, 1, n){
		if (dif[i]<0) fst -=dif[i], dif[i] = 0;
		fst += dif[i];
		pq.push(dif[i]), pq.push(dif[i]);
		pq.pop();
	}
	while(sz(pq)){
		ll a = pq.top();pq.pop();
		fst -= min(a, dif[n]);
	}
	cout << fst << endl;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int testcase=1;
    // cin >> testcase;
    while (testcase--)
    {
        solve();
    }
}

Compilation message

bulves.cpp: In function 'void setIO(std::string)':
bulves.cpp:95:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:96:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 17 ms 1700 KB Output is correct
5 Correct 36 ms 2912 KB Output is correct
6 Correct 115 ms 7756 KB Output is correct
7 Correct 174 ms 15164 KB Output is correct
8 Correct 202 ms 13304 KB Output is correct
9 Correct 173 ms 12656 KB Output is correct
10 Correct 139 ms 10348 KB Output is correct
11 Correct 144 ms 10348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 17 ms 1700 KB Output is correct
5 Correct 36 ms 2912 KB Output is correct
6 Correct 115 ms 7756 KB Output is correct
7 Correct 174 ms 15164 KB Output is correct
8 Correct 202 ms 13304 KB Output is correct
9 Correct 173 ms 12656 KB Output is correct
10 Correct 139 ms 10348 KB Output is correct
11 Correct 144 ms 10348 KB Output is correct
12 Correct 54 ms 4232 KB Output is correct
13 Correct 138 ms 10936 KB Output is correct
14 Correct 178 ms 15232 KB Output is correct
15 Correct 199 ms 13420 KB Output is correct
16 Correct 219 ms 12668 KB Output is correct
17 Correct 139 ms 10352 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 17 ms 1700 KB Output is correct
12 Correct 36 ms 2912 KB Output is correct
13 Correct 115 ms 7756 KB Output is correct
14 Correct 174 ms 15164 KB Output is correct
15 Correct 202 ms 13304 KB Output is correct
16 Correct 173 ms 12656 KB Output is correct
17 Correct 139 ms 10348 KB Output is correct
18 Correct 144 ms 10348 KB Output is correct
19 Correct 54 ms 4232 KB Output is correct
20 Correct 138 ms 10936 KB Output is correct
21 Correct 178 ms 15232 KB Output is correct
22 Correct 199 ms 13420 KB Output is correct
23 Correct 219 ms 12668 KB Output is correct
24 Correct 139 ms 10352 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 60 ms 4128 KB Output is correct
34 Correct 139 ms 10940 KB Output is correct
35 Correct 240 ms 15220 KB Output is correct
36 Correct 229 ms 12788 KB Output is correct
37 Correct 202 ms 13372 KB Output is correct
38 Correct 230 ms 15152 KB Output is correct
39 Correct 160 ms 11332 KB Output is correct
40 Correct 173 ms 10884 KB Output is correct
41 Correct 146 ms 10348 KB Output is correct
42 Correct 140 ms 10424 KB Output is correct
43 Correct 140 ms 10364 KB Output is correct
44 Correct 142 ms 10360 KB Output is correct
45 Correct 229 ms 15220 KB Output is correct
46 Correct 170 ms 10740 KB Output is correct
47 Correct 152 ms 10172 KB Output is correct