Skip to content

Commit f5665b5

Browse files
committed
Just Code
0 parents  commit f5665b5

19 files changed

+852
-0
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"iostream": "cpp"
4+
}
5+
}

1312D.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
LL fme(int x, int y){
13+
LL res = 1;
14+
while(y){
15+
if(y&1) res = (res*x)%mod;
16+
y/=2;
17+
x=(x*x)%mod;
18+
}
19+
return res;
20+
}
21+
22+
LL gcdextended(LL a, LL b, LL *x, LL *y){
23+
if(a==0) {
24+
*x=0;*y=1;
25+
return b;
26+
}
27+
LL x1,y1;
28+
LL g = gcdextended(b%a, a, &x1, &y1);
29+
*x = y1 - (b/a) * x1;
30+
*y = x1;
31+
return g;
32+
}
33+
34+
LL invmod(LL c){
35+
LL x,y;
36+
LL g = gcdextended(c,mod,&x,&y);
37+
return (x%mod + mod)%mod;
38+
}
39+
40+
int main(){
41+
int n,m; cin>>n>>m;
42+
LL f[2*MAX];f[0]=1;f[1]=1;
43+
FOR(i,2,2*MAX) f[i]=(i*f[i-1])%998244353;
44+
LL mcr = (f[m]*invmod( (f[n-1]*f[m-n+1])%mod ))%mod;
45+
LL ans = (mcr*(n-2))%mod;
46+
LL e = fme(2,n-3);
47+
ans = (ans*e)%mod;
48+
cout<<ans;
49+
}

1325C.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
13+
int main(){
14+
int n; cin>>n;
15+
vector<int>adj[MAX]; vector<pair<int,int>> v;
16+
FOR(i,0,n-1) {int x,y; cin>>x>>y; adj[x].push_back(y); adj[y].push_back(x);v.push_back({x,y});}
17+
map<pair<int,int>,int> m;
18+
int k=0,j=n-1;
19+
FOR(i,1,n+1){
20+
if(adj[i].size()==1){
21+
m[{i,adj[i][0]}]=k;
22+
k++;
23+
}
24+
else{
25+
m[{i,adj[i][0]}]=j;
26+
j--;
27+
}
28+
}
29+
FOR(i,0,v.size()) cout<<m[{v[i].first, v[i].second}]<<"\n";
30+
}

1326A.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
13+
int main(){
14+
fastio;
15+
int t; cin>>t;
16+
while (t--)
17+
{
18+
int n; cin>>n;
19+
if(n==1) cout<<-1;
20+
else {
21+
cout<<2;
22+
FOR(i,1,n) cout<<9;
23+
}
24+
cout<<"\n";
25+
}
26+
27+
}

1326B.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
13+
int main(){
14+
fastio;
15+
int n; cin>>n;
16+
int b[n],a[n],x[n]; FOR(i,0,n) cin>>b[i];
17+
x[0]=0;a[0]=b[0];
18+
int m=a[0];
19+
FOR(i,1,n) {
20+
a[i] = b[i]+m;
21+
m=max(a[i],m);
22+
}
23+
FOR(i,0,n) cout<<a[i]<<" ";
24+
}

1326C.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
13+
int main(){
14+
fastio;
15+
int n,k; cin>>n>>k;
16+
int a[n],b[2*MAX]; FOR(i,0,n) {cin>>a[i];b[a[i]]=i;}
17+
LL sum=0,temp=n; FOR(i,0,k) {sum+=temp; temp--;}
18+
temp=n;vector<int>v;
19+
FOR(i,0,k) {v.push_back(b[temp]); temp--;}
20+
LL p=1;
21+
sort(v.begin(),v.end());
22+
FOR(i,0,k-1) {
23+
temp = v[i+1]-v[i];
24+
p=(p*temp)%mod;
25+
}
26+
cout<<sum<<" "<<p;
27+
}

1326D1.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
13+
void lp(vector<int> &v, int n, string s){
14+
int i=0,j=1; v[i]=0;
15+
while(j<n){
16+
if(s[i]==s[j]){
17+
v[j]=++i;
18+
j++;
19+
}
20+
else {
21+
if(i!=0){
22+
i = v[i-1];
23+
}
24+
else {
25+
v[j]=0;
26+
j++;
27+
}
28+
}
29+
}
30+
}
31+
int main(){
32+
fastio;
33+
int t; cin>>t;
34+
while(t--){
35+
string s,p; cin>>s;
36+
int i=0,n=s.size();
37+
while(i<=n/2 && s[i]==s[n-i-1]) i++;
38+
if(n-2*i>0) p= s.substr(i,n-2*i);
39+
else {
40+
cout<<s<<"\n";
41+
continue;
42+
}
43+
string rv = p;
44+
reverse(rv.begin(),rv.end());
45+
string s1 = p+'@'+rv,s2=rv+'@'+p;
46+
n=s1.size();
47+
vector<int>v1(n),v2(n);
48+
lp(v1,n,s1);
49+
lp(v2,n,s2);
50+
int m1=v1[n-1],m2=v2[n-1];
51+
//cout<<m1<<" "<<m2<<" "<<s1<<" ";
52+
if(i==0 && m1==0 && m2==0) cout<<s[0];
53+
else if(m1>=m2){
54+
FOR(j,0,i) cout<<s[j];
55+
FOR(j,0,m1) cout<<s1[j];
56+
ROF(j,i-1,0) cout<<s[j];
57+
} else {
58+
FOR(j,0,i) cout<<s[j];
59+
FOR(j,0,m2) cout<<s2[j];
60+
ROF(j,i-1,0) cout<<s[j];
61+
}
62+
cout<<"\n";
63+
}
64+
}

1327A.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
13+
int main(){
14+
fastio;
15+
int t; cin>>t;
16+
while(t--){
17+
LL n,k; cin>>n>>k;
18+
LL s = (k*(k-1))/2;
19+
if((n-k)%2==0 && (n-k)/2>=s) cout<<"YES";
20+
else cout<<"NO";
21+
cout<<"\n";
22+
}
23+
}

1327B.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
13+
int main(){
14+
fastio;
15+
int t; cin>>t;
16+
while(t--){
17+
int n; cin>>n;
18+
bool d[MAX]={false},k[MAX]={false};
19+
FOR(i,1,n+1){
20+
int x; cin>>x;
21+
FOR(j,0,x) {int y; cin>>y;
22+
if(d[i]) continue; if(!k[y]) {d[i]=true; k[y]=true;}
23+
}
24+
}
25+
26+
int x=0,y=0;
27+
FOR(i,1,n+1) if(!d[i]){x=i; break;}
28+
FOR(i,1,n+1) if(!k[i]){y=i; break;}
29+
if(x && y){
30+
cout<<"IMPROVE"<<"\n";
31+
cout<<x<<" "<<y;
32+
}
33+
else {
34+
cout<<"OPTIMAL";
35+
}
36+
cout<<"\n";
37+
}
38+
}

1327C.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
5+
#define LL long long
6+
#define mod 998244353
7+
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
8+
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
9+
10+
const long long INF = 1e18;
11+
const long long MAX = 1e5+10;
12+
13+
int main(){
14+
fastio;
15+
int n,m,k; cin>>n>>m>>k;
16+
vector<pair<int,int>>s;
17+
vector<vector<int>>v(k+1,vector<int>(2,0));
18+
FOR(i,0,k){
19+
int x,y; cin>>x>>y;
20+
s.push_back({x,y});
21+
}
22+
FOR(i,0,k){
23+
int x,y; cin>>x>>y;
24+
v[i][0]+=x-s[i].first;
25+
v[i][1]+=y-s[i].second;
26+
}
27+
string p="";
28+
29+
}

Untitled-1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define rep(i,a,n) for (int i=a;i<n;i++)
4+
#define per(i,a,n) for (int i=n-1;i>=a;i--)
5+
#define pb push_back
6+
#define mp make_pair
7+
#define all(x) (x).begin(),(x).end()
8+
#define fi first
9+
#define se second
10+
#define SZ(x) ((int)(x).size())
11+
typedef vector<int> VI;
12+
typedef long long ll;
13+
typedef pair<int,int> PII;
14+
typedef double db;
15+
mt19937 mrand(random_device{}());
16+
const ll mod=1000000007;
17+
int rnd(int x) { return mrand() % x;}
18+
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
19+
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
20+
// head
21+
22+
const int N=201000;
23+
int _,n,matl[N],matr[N];
24+
int main() {
25+
for (scanf("%d",&_);_;_--) {
26+
scanf("%d",&n);
27+
int cnt=0;
28+
rep(i,1,n+1) matr[i]=0,matl[i]=0;
29+
rep(i,1,n+1) {
30+
int k,x;
31+
scanf("%d",&k);
32+
rep(j,0,k) {
33+
scanf("%d",&x);
34+
if (matl[i]||matr[x]) continue;
35+
matr[x]=1; matl[i]=1; cnt++;
36+
}
37+
}
38+
if (cnt==n) {
39+
puts("OPTIMAL");
40+
} else {
41+
int pl=0,pr=0;
42+
rep(i,1,n+1) if (matl[i]==0) pl=i;
43+
rep(i,1,n+1) if (matr[i]==0) pr=i;
44+
puts("IMPROVE");
45+
printf("%d %d\n",pl,pr);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)