QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152808#7078. Tower of the SorcererPetroTarnavskyi#WA 103ms12268kbC++172.6kb2023-08-28 20:54:312023-08-28 20:54:32

Judging History

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

  • [2023-08-28 20:54:32]
  • 评测
  • 测评结果:WA
  • 用时:103ms
  • 内存:12268kb
  • [2023-08-28 20:54:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))

#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int INF = 1000'000'447;
const LL LINF = 1ll * INF * INF;


struct Segtree
{
	int n;
	vector<int> t;
	
	void init(int nn)
	{
		n = 1;
		while (n < nn) n *= 2;
		t.assign(n * 2, INF);
	}
	
	int mn(int v, int tl, int tr, int l, int r)
	{
		if (l <= tl && tr <= r)
			return t[v];
		if (l >= tr || tl >= r)
			return INF;
		int m = (tl + tr) / 2;
		return min(mn(v * 2, tl, m, l, r), mn(v * 2 + 1, m, tr, l, r));
	}
	
	int mn(int l, int r)
	{
		return mn(1, 0, n, l, r);
	}
	
	void change(int v, int l, int r, int i, int x)
	{
		if (l + 1 == r)
		{
			t[v] = x;
			return;
		}
		int m = (l + r) / 2;
		if (i < m)
			change(v * 2, l, m, i, x);
		else
			change(v * 2 + 1, m, r, i, x);
		t[v] = min(t[v * 2], t[v * 2 + 1]);
	}
	
	void change(int i, int x)
	{
		change(1, 0, n, i, x);
	}
};

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, d;
	cin >> n >> d;
	
	Segtree st;
	st.init(n + 1);
	
	vector<PII> a(n);
	int mx = d;
	FOR (i, 0, n)
	{
		cin >> a[i].F >> a[i].S;
		mx = max(mx, a[i].F);
	}
	
	a.PB({d, 0});
	sort(ALL(a));
	int b = lower_bound(ALL(a), MP(d, 0)) - a.begin();
	n++;
	
	//VI suf(n);
	//RFOR (i, n, 0)
	//{
	//	suf[i] = a[i].S;
	//	if (i != n - 1)
	//		suf[i] = min(suf[i], suf[i + 1]);
	//}
	
	unordered_map<int, int> m;
	m.reserve(1e6);
	FOR (i, 0, n) m[a[i].S] = i;
	
	vector<LL> pref(n + 1);
	FOR (i, 0, n)
	{
		LL val = (a[i].S - 1) / mx * a[i].F;
		pref[i + 1] = pref[i] + val;
	}
	vector<LL> dp(n, LINF);
	dp[b] = pref[b];
	st.change(b, pref[b] - pref[b + 1]);
	
	FOR (i, b + 1, n)
	{
		//if (i != n - 1 && a[i].S > suf[i]) continue;
		int x = 1;
		int l = lower_bound(ALL(a), MP(x, -1)) - a.begin();
		int hp = a[i].S - 1;
		while (x <= hp)
		{
			int k = hp / x;
			int nx = hp / k;
			int r = lower_bound(ALL(a), MP(nx + 1, -1)) - a.begin();
			dp[i] = min(dp[i], pref[i] + st.mn(l, r) + k * a[i].F);
			x = nx + 1;
			l = r;
		}
		int r = n;
		dp[i] = min(dp[i], pref[i] + st.mn(l, r));
		st.change(i, dp[i] - pref[i + 1]);
	}
	//FOR (i, 0, n) cerr << dp[i] << ' ';
	//cerr << '\n';
	cout << dp[n - 1] << '\n';

	cerr << db(clock()) / CLOCKS_PER_SEC << '\n';
	
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 11232kb

input:

4 1
3 2
4 4
5 6
1 6

output:

9

result:

ok single line: '9'

Test #2:

score: -100
Wrong Answer
time: 103ms
memory: 12268kb

input:

5000 679
84191 46042
81916 66659
74636 72443
10252 57443
21838 54620
84896 58466
20832 29643
45949 20576
50399 51434
56472 90759
68909 94348
39459 1731
81207 17614
26465 11775
93861 24936
25017 64663
21042 37570
32903 68583
68840 58347
93849 10841
10190 77131
10595 1959
57163 59047
16066 89850
73741...

output:

-1147449649

result:

wrong answer 1st lines differ - expected: '0', found: '-1147449649'