QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69013#5117. Find MaximumzhuibaoWA 4ms3516kbC++201.6kb2022-12-22 15:23:532022-12-22 15:23:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-22 15:23:54]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3516kb
  • [2022-12-22 15:23:53]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) 
#include<unordered_map>
#include<unordered_set>
#include<bits/stdc++.h>
#include<array>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pi;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(ll i=a;i<=n;i++)
#define ref(i,n,a) for(ll i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("out.txt", ios::out);
//ifstream fin("in.txt", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------

int l, r;
int cnt[50];
vector<int>vl, vr;

void solve()
{
	vl.clear();
	vr.clear();
	mem(cnt, 0);
	cin >> l >> r;
	int tmp = l;
	while (tmp)
	{
		vl.emplace_back(tmp % 3);
		tmp /= 3;
	}
	tmp = r;
	while (tmp)
	{
		vr.emplace_back(tmp % 3);
		tmp /= 3;
	}
	int ans = 0;
	ans = vr.size();
	for (int it : vr)
	{
		ans += it;
	}
	int n = vr.size();
	bool flag = 0;
	int sum = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		int res = n + sum;
		sum += vr[i];
		if (vr[i] == 0)continue;
		if (vl.size() == n && !flag && vr[i] == vl[i])continue;
		if (i == n - 1 && vr[i] == 1)res--;
		res += 2 * i;
		ans = max(ans, res);
		if (vl.size() == n && vr[i] > vl[i])flag |= 1;
	}
	cout << ans << endl;
}

signed main()
{
	ac;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3256kb

input:

10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

output:

3
3
4
5
3
4
5
4
5
5

result:

ok 10 numbers

Test #2:

score: -100
Wrong Answer
time: 4ms
memory: 3516kb

input:

5050
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61...

output:

2
3
3
4
5
4
5
6
6
6
6
6
6
7
6
7
8
7
7
7
7
7
8
7
8
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
10
9
9
9
9
9
10
9
10
11
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
11
10
10
10
10
10
11
10
11
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
3
3
4
5
4
5
6
6
6
6
6
6
7
6
7
8
7
7
7
7
7
8
7
8
9...

result:

wrong answer 6th numbers differ - expected: '5', found: '4'