QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385102#2160. CardiologyKevin5307#AC ✓26ms40832kbC++231.8kb2024-04-10 15:31:512024-04-10 15:31:52

Judging History

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

  • [2024-04-10 15:31:52]
  • 评测
  • 测评结果:AC
  • 用时:26ms
  • 内存:40832kb
  • [2024-04-10 15:31:51]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int nxt[1001000];
vector<int> G[1001000];
int dist[1001000];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int r,c;
	cin>>r>>c;
	int p=-1,ax=-1,ay=-1,s=-1;
	int d=0x3f3f3f3f;
	for(int i=1;i<=c;i++)
	{
		// (x-1)*m+y=x+(i-1)*r
		// (m-1)x=(i-1)*r+m-y
		int rem=(1ll*(i-1)*r+c)%(c-1);
		if(rem==1&&(1ll*(i-1)*r+c-rem)/(c-1)>1) continue;
		int y=rem;
		if(!y) y+=c-1;
		int x=(1ll*(i-1)*r+c-y)/(c-1);
		if(x<1||x>r||y<1||y>c) continue;
		int dist=0x3f3f3f3f;
		for(int j=(r+1)/2;j<=r/2+1;j++)
			for(int k=(c+1)/2;k<=c/2+1;k++)
				dist=min(dist,abs(j-x)+abs(k-y));
		if(dist<d)
		{
			d=dist;
			p=i;
			ax=x;
			ay=y;
		}
	}
	for(int i=1;i<=r;i++)
	{
		ll val=1ll*(p-1)*r+i;
		nxt[i]=(val+c-1)/c;
		if(i!=nxt[i])
			G[nxt[i]].pb(i);
	}
	memset(dist,-1,sizeof(dist));
	queue<int> q;
	for(int i=1;i<=r;i++)
		if(i==nxt[i])
		{
			dist[i]=0;
			q.push(i);
		}
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(auto y:G[x])
		{
			dist[y]=dist[x]+1;
			q.push(y);
		}
	}
	cout<<p<<" "<<ax<<" "<<ay<<" "<<*max_element(dist+1,dist+r+1)+1<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 9644kb

input:

6666 966364

output:

473832 3269 483163 2

result:

ok single line: '473832 3269 483163 2'

Test #2:

score: 0
Accepted
time: 9ms
memory: 9584kb

input:

36 906986

output:

12598 1 453493 2

result:

ok single line: '12598 1 453493 2'

Test #3:

score: 0
Accepted
time: 14ms
memory: 16528kb

input:

704877 297616

output:

148803 352426 140980 3

result:

ok single line: '148803 352426 140980 3'

Test #4:

score: 0
Accepted
time: 18ms
memory: 21924kb

input:

1000000 1000000

output:

500000 500000 500000 2

result:

ok single line: '500000 500000 500000 2'

Test #5:

score: 0
Accepted
time: 0ms
memory: 9616kb

input:

2 2

output:

1 1 1 2

result:

ok single line: '1 1 1 2'

Test #6:

score: 0
Accepted
time: 26ms
memory: 40832kb

input:

1000000 2

output:

1 1 1 21

result:

ok single line: '1 1 1 21'

Test #7:

score: 0
Accepted
time: 14ms
memory: 9520kb

input:

2 1000000

output:

250001 1 500001 2

result:

ok single line: '250001 1 500001 2'

Test #8:

score: 0
Accepted
time: 16ms
memory: 20696kb

input:

985391 511611

output:

255806 492696 255806 3

result:

ok single line: '255806 492696 255806 3'

Test #9:

score: 0
Accepted
time: 13ms
memory: 14848kb

input:

435766 614914

output:

304739 215957 307481 2

result:

ok single line: '304739 215957 307481 2'

Test #10:

score: 0
Accepted
time: 10ms
memory: 18392kb

input:

818196 58

output:

29 401921 49 5

result:

ok single line: '29 401921 49 5'

Test #11:

score: 0
Accepted
time: 10ms
memory: 14668kb

input:

401765 19

output:

10 200883 10 6

result:

ok single line: '10 200883 10 6'

Test #12:

score: 0
Accepted
time: 9ms
memory: 9748kb

input:

95 912669

output:

456335 48 456335 2

result:

ok single line: '456335 48 456335 2'

Test #13:

score: 0
Accepted
time: 6ms
memory: 9552kb

input:

81 429950

output:

2655 1 214975 2

result:

ok single line: '2655 1 214975 2'

Test #14:

score: 0
Accepted
time: 19ms
memory: 18984kb

input:

999956 999959

output:

249991 249990 499979 3

result:

ok single line: '249991 249990 499979 3'

Test #15:

score: 0
Accepted
time: 20ms
memory: 19816kb

input:

999935 999946

output:

449976 449971 499976 3

result:

ok single line: '449976 449971 499976 3'

Test #16:

score: 0
Accepted
time: 17ms
memory: 20688kb

input:

999951 999952

output:

1 1 1 2

result:

ok single line: '1 1 1 2'

Test #17:

score: 0
Accepted
time: 3ms
memory: 10112kb

input:

106352 224337

output:

112111 53149 112993 2

result:

ok single line: '112111 53149 112993 2'

Test #18:

score: 0
Accepted
time: 13ms
memory: 17960kb

input:

651870 786333

output:

392936 325744 393775 2

result:

ok single line: '392936 325744 393775 2'

Test #19:

score: 0
Accepted
time: 26ms
memory: 20676kb

input:

838522 972888

output:

486249 419093 486853 2

result:

ok single line: '486249 419093 486853 2'