牛客挑战赛73新手の题解
A:S 老师的公式
签到题
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
const int N = 2e5 + 5;
const int mod = 10086;
map<char, int> mp;
int n, m;
signed main() {
cin >> n;
int num1 = (1 + n) * n / 2;
int sum = 1;
for (int i = 1; i <= n; i++) {
sum *= i;
sum %= num1;
}
cout << gcd(num1, sum) << endl;
return 0;
}
B:S 老师的签到
需要用广度搜索加标记数组去减少空间使用量
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
const int N = 2e5 + 5;
const int mod = 10086;
int n, m;
char a[1500][1500];
string ans;
vector<pair<int,int>>ve;
int vis[1500][1500];
void bfs(){
queue<pair<int,int>>q;
q.push({0, 0});
while(!q.empty()){
int num=q.size();
char s='z';
int f=0;
for(int i=0;i<num;i++){
pair op=q.front();
q.pop();
int x=op.first;
int y=op.second;
if(vis[x][y])continue;
vis[x][y]=1;
s=min(a[x][y],s);
if(x==n-1&&y==m-1) {
f=1;
break;
}
if(x+1<n&&y+1<m){
if(a[x+1][y]==a[x][y+1]){
ve.push_back({x+1,y});
ve.push_back({x , y+1});
}else if(a[x+1][y]<a[x][y+1]){
ve.clear();
ve.push_back({x+1,y});
}else{
ve.clear();
ve.push_back({x,y+1});
}
continue;
}
if(x+1<n){
ve.push_back({x+1,y});
}
if(y+1<m){
ve.push_back({x , y+1});
}
}
ans+=s;
if(f==1)return ;
for(auto it:ve){
q.push({it.first,it.second});
}
}
}
signed main() {
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
bfs();
cout<<ans<<endl;
return 0;
}
C:S 老师的求和
数学公式推导加逆元
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
const int N = 2e5 + 5;
const int mod = 998244353;
int n, m;
int a,b,x;
int ksm(int X,int y){
int res=1;
while(y){
if(y&1)res=res*X%mod;
X=X*X%mod;
y>>=1;
}
return res%mod;
}
int L1(int A,int B,int X){
int op=A*X%mod;
return (op+B)%mod;
}
int L2(int A,int B,int X){
int op=X*B%mod;
int num=(A*(1+X)%mod*X%mod*ksm(2,mod-2))%mod;
return (op+num)%mod;
}
int L3(int A,int B,int X){
int op=((1+X)*X%mod*B%mod*ksm(2,mod-2))%mod;
int num=(A*X%mod*(X+1)%mod*(X+2)%mod*ksm(6,mod-2))%mod;
return (op+num)%mod;
}
int L4(int A,int B,int X){
int op=(B*X%mod*(X+1)%mod*(X+2)%mod*ksm(6,mod-2))%mod;
int num=(A*X%mod*(X+1)%mod*(X+2)%mod*(X+3)%mod*ksm(24,mod-2))%mod;
return (op+num)%mod;
}
signed main() {
int _;
cin>>_;
while(_--){
cin>>a>>b>>x;
cout<<L1(a,b,x)<<" "<<L2(a,b,x)<<" "<<L3(a,b,x)<<" "<<L4(a,b,x)<<endl;
}
return 0;
}