QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397170#4398. Luxury cruise shipDiuAC ✓1ms3904kbC++141002b2024-04-23 18:49:262024-04-23 18:49:27

Judging History

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

  • [2024-04-23 18:49:27]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3904kb
  • [2024-04-23 18:49:26]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

inline int read(){
	int x = 0, f = 1; char c = getchar();
	while(c < '0' || c > '9'){if(c == '-')f = -1; c = getchar();}
	while(c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + c - '0'; c = getchar();}
	return x * f;
}
int T;
ll n;
void exgcd(ll a, ll b, ll &x, ll &y){
	if(!b){
		x = 1, y = 0;
		return;
	}
	exgcd(b, a % b, y, x);
	y -= a / b * x;
}
ll check(ll t){
	ll x,y;
	exgcd(7ll,31ll,x,y);
	x*=t,y*=t;
	if(x>=0){
		ll d=(x)/31;
		x-=d*31ll;
		y+=d*7ll;
	}
	if(x<0){
		ll d=(-x+30)/31;
		x+=d*31ll;
		y-=d*7ll;
	}
	if(y<0)return -1;
	return x+y;
}
int main(){
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	scanf("%d",&T);
	for(;T--;){
		scanf("%lld",&n);
		ll t=n%365,now=n/365,ans=n;
		for(int i=0;i<=7&&now>=0;i++){
			ll x=check(t);
			if(x!=-1)ans=min(ans,x+now);
			--now,t+=365;
		}
		if(ans==n)puts("-1");
		else printf("%lld\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101...

output:

-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
-1
-1
-1
4
-1
-1
1
-1
-1
-1
5
-1
-1
2
-1
-1
-1
6
-1
-1
3
-1
-1
-1
7
-1
-1
4
-1
-1
-1
8
-1
-1
5
-1
-1
2
9
-1
-1
6
-1
-1
3
10
-1
-1
7
-1
-1
4
11
-1
-1
8
-1
-1
5
12
-1
-1
9
-1
-1
6
13
-1
3
10
-1
-1
7
14
-1
4
11
-1
-1
8
15
-1
5
12
-1
-...

result:

ok 1000 lines