QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345366#3418. Highway of the FuturePetroTarnavskyi#TL 20ms7600kbC++202.0kb2024-03-06 21:00:022024-03-06 21:00:02

Judging History

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

  • [2024-03-06 21:00:02]
  • 评测
  • 测评结果:TL
  • 用时:20ms
  • 内存:7600kb
  • [2024-03-06 21:00:02]
  • 提交

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 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 MX = 1 << 20;
const int X = 101;
const int Y = 10047;

int n;
int cnt[MX];
VI vecs[X];
vector<PII> vecPairs[X];
int g[X][Y];

void precalc()
{
	FOR(i, 1, X)
		FOR(j, 0, Y)
			g[i][j] = gcd(i, j);
}

void solve()
{
	FOR(i, 0, X)
	{
		vecs[i].clear();
		vecPairs[i].clear();
	}
	FOR(i, 0, n)
	{
		int t, v;
		cin >> t >> v;
		vecs[v].PB(v * t);
	}
	FOR(k, 1, X)
	{
		sort(ALL(vecs[k]));
		for (int j = 0; j < SZ(vecs[k]); )
		{
			int l = j;
			while (l < SZ(vecs[k]) && vecs[k][l] == vecs[k][j])
			{
				l++;
			}
			vecPairs[k].PB({vecs[k][j], l - j});
			j = l;
		}
	}
	int ans = 0;
	FOR(x1, 1, X)
	{
		for (auto [y1, c] : vecPairs[x1])
		{
			int cur = 0;
			FOR(x2, x1 + 1, X)
			{
				auto le = lower_bound(ALL(vecPairs[x2]), MP(y1, 0)),
					ri = lower_bound(ALL(vecPairs[x2]), MP(y1 + (x2 - x1) * 100 + 1, 0));
				int dx = x2 - x1;
				int dx2 = Y * dx - y1;
				for (auto it = le; it != ri; it++)
				{
					int gc = g[dx][it->F - y1];
					int& res = cnt[(dx2 + it->F) / gc];
					res += it->S;
					cur = max(cur, res);
				}
			}
			FOR(x2, x1 + 1, X)
			{
				auto le = lower_bound(ALL(vecPairs[x2]), MP(y1, 0)),
					ri = lower_bound(ALL(vecPairs[x2]), MP(y1 + (x2 - x1) * 100 + 1, 0));
				int dx = x2 - x1;
				int dx2 = Y * dx - y1;
				for (auto it = le; it != ri; it++)
				{
					int gc = g[dx][it->F - y1];
					cnt[(dx2 + it->F) / gc] -= it->S;
				}
			}
			ans = max(ans, cur + c);
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	precalc();
	while (cin >> n)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 20ms
memory: 7600kb

input:

4
10 10
10 10
15 20
15 20
3
100 100
100 1
100 1

output:

4
3

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

4384
887 78
916 94
336 87
493 50
422 63
28 91
60 64
927 41
427 73
737 12
369 68
430 83
531 63
124 68
136 30
803 23
59 70
168 94
457 12
43 30
374 22
920 85
538 99
325 16
371 14
527 92
981 57
874 63
171 97
282 6
926 85
328 37
506 47
730 14
858 25
896 83
546 15
368 35
365 44
751 88
809 77
179 89
585 4
...

output:


result: