UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214371#2678. Small Multipleerican308ms5144kbC++111.6kb2024-11-18 18:59:432024-11-19 08:26:49

answer

// Problem: I - Escape
// Contest: Virtual Judge - 思维
// URL: https://vjudge.net/contest/670080#problem/I
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Challenger: Erica N
// ----
// 
#include<bits/stdc++.h>

using namespace std;
#define rd read()
#define ull unsigned long long
#define int long long 
#define pb push_back
#define itn int
#define ps second 
#define pf first


#define rd read()
int read(){
  int xx = 0, ff = 1;char ch = getchar();
  while (ch < '0' || ch > '9'){
    if (ch == '-')ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
  return xx * ff;
}
#define zerol = 1
#ifdef zerol
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() {cerr << endl;}
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
	for (auto v: a) cerr << v << ' ';err(x...);
}
template<typename T, typename... A>
void err(T a, A... x) {
	cerr << a << ' ';err(x...);
}
#else
#define dbg(...)
#endif
const int N=5e5+5;
const ull P=137;
const int INF=1e18+7;
/*

策略


*/	



int f[N];
struct Node{
	int r=0;
	int s;
};
queue <Node> q;

signed main(){
	int k=rd;
    int m=rd;
	
	for(int i=0;i<N;i++)f[i]=INF;
	
	Node cur,cur2;
	for(int i=1;i<m;i++){
		cur.r=i%k;
		cur.s=i;
		q.push(cur);
	}
	while(!q.empty()){
		cur2=q.front();
		q.pop();
		if(f[cur2.r]<=cur2.s)
			continue;
		f[cur2.r]=cur2.s;
		for(int i=0;i<=m-1;i++){
			cur.r=(m*cur2.r+i)%k;
			cur.s=cur2.s+i;
			q.push(cur);
		}
	}
	cout<<f[0];
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 5108kb

input:

32 4

output:

1

result:

ok single line: '1'

Test #2:

score: 5
Accepted
time: 0ms
memory: 5116kb

input:

25 6

output:

5

result:

ok single line: '5'

Test #3:

score: 5
Accepted
time: 4ms
memory: 5108kb

input:

19 3

output:

2

result:

ok single line: '2'

Test #4:

score: 5
Accepted
time: 0ms
memory: 5128kb

input:

64 7

output:

4

result:

ok single line: '4'

Test #5:

score: 5
Accepted
time: 0ms
memory: 5144kb

input:

86 10

output:

3

result:

ok single line: '3'

Test #6:

score: 5
Accepted
time: 4ms
memory: 5104kb

input:

17 2

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Runtime Error

input:

937761 10

output:


result:


Test #8:

score: 0
Runtime Error

input:

788944 8

output:


result:


Test #9:

score: 0
Runtime Error

input:

573314 3

output:


result:


Test #10:

score: 0
Runtime Error

input:

785883 5

output:


result:


Test #11:

score: 0
Runtime Error

input:

769025 7

output:


result:


Test #12:

score: 0
Runtime Error

input:

909894 4

output:


result:


Test #13:

score: 0
Runtime Error

input:

585472 9

output:


result:


Test #14:

score: 0
Runtime Error

input:

795020 5

output:


result:


Test #15:

score: 0
Runtime Error

input:

514716 8

output:


result:


Test #16:

score: 0
Runtime Error

input:

984458 5

output:


result:


Test #17:

score: 0
Runtime Error

input:

645285 2

output:


result:


Test #18:

score: 0
Runtime Error

input:

694328 9

output:


result:


Test #19:

score: 0
Runtime Error

input:

698907 6

output:


result:


Test #20:

score: 0
Runtime Error

input:

994036 7

output:


result: