Skip to content

Commit a0872b3

Browse files
authored
dasd
1 parent 7bdb291 commit a0872b3

15 files changed

+558
-64
lines changed

113a.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 1000000007
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+
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
10+
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
11+
12+
const long long INF = 1e18;
13+
const long long MAX = 1e5+10;
14+
15+
int main(){
16+
fastio;
17+
int t; cin>>t;
18+
while(t--){
19+
int n; cin>>n;
20+
string s; cin>>s;
21+
bool ok = false;
22+
FOR(i,0,n){
23+
int a=0,b=0;
24+
FOR(j,i,n){
25+
if(s[j]=='a') a++;
26+
else b++;
27+
if(a==b) {
28+
cout<<i+1<<" "<<j+1<<"\n";
29+
ok = true;
30+
break;
31+
}
32+
}
33+
if(ok) break;
34+
}
35+
if(!ok) cout<<-1<<" "<<-1<<"\n";
36+
}
37+
}

113c.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio \
5+
ios_base::sync_with_stdio(0); \
6+
cin.tie(0)
7+
#define LL long long
8+
#define mod 998244353
9+
#define FOR(i, j, k) for (int i = j; i < k; i++)
10+
#define ROF(i, j, k) for (int i = j; i >= k; i--)
11+
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
12+
#define time__(d) for (long blockTime = 0; (blockTime == 0 ? (blockTime = clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
13+
14+
const long long INF = 1e18;
15+
const long long MAX = 1e5 + 10;
16+
int gcd(int a, int b);
17+
18+
// To compute x raised to power y under modulo m
19+
int power(int x, unsigned int y, unsigned int m);
20+
21+
long long calculate(long long p,
22+
long long q)
23+
{
24+
long long expo;
25+
expo = mod - 2;
26+
27+
// Loop to find the value
28+
// until the expo is not zero
29+
while (expo)
30+
{
31+
32+
// Multiply p with q
33+
// if expo is odd
34+
if (expo & 1)
35+
{
36+
p = ((p * q) % mod + mod)%mod;
37+
}
38+
q = ((q * q) % mod + mod)%mod;
39+
40+
// Reduce the value of
41+
// expo by 2
42+
expo >>= 1;
43+
}
44+
return p;
45+
}
46+
47+
int main()
48+
{
49+
fastio;
50+
int t;
51+
cin >> t;
52+
LL p[2 * MAX];
53+
p[0] = 1;
54+
FOR(i, 1, 2 * MAX)
55+
p[i] = ((i * p[i - 1]) % mod + mod)%mod;
56+
while (t--)
57+
{
58+
int n;
59+
cin >> n;
60+
int a[n];
61+
map<int, int> m;
62+
FOR(i, 0, n)
63+
cin >> a[i],
64+
m[a[i]]++;
65+
sort(a, a + n);
66+
if (n == 1)
67+
{
68+
if (m[a[0]] > 1)
69+
cout << 0 << "\n";
70+
else
71+
cout << 1 << "\n";
72+
continue;
73+
}
74+
if (a[n - 1] - a[n - 2] > 1)
75+
{
76+
cout << 0 << "\n";
77+
continue;
78+
}
79+
if (m[a[n - 1]] > 1)
80+
{
81+
cout << p[n] << "\n";
82+
continue;
83+
}
84+
LL l = p[n - m[a[n - 2]] - 1], k = m[a[n - 2]];
85+
LL ans = 0;
86+
FOR(i, k, n)
87+
{
88+
int r = calculate(p[i], p[i - k]);
89+
r = ((r * l) % mod + mod)%mod;
90+
ans += r;
91+
}
92+
ans = ((p[n] - ans) % mod + mod) % mod;
93+
cout << ans << "\n";
94+
}
95+
}

a.out

-51 KB
Binary file not shown.

abh.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
14+
int main(){
15+
fastio;
16+
int t=1;// cin>>t;
17+
while(t--){
18+
int n,m; cin>>n>>m;
19+
char a[n][m];
20+
FOR(i,0,n) FOR(j,0,m) cin>>a[i][j];
21+
FOR(i,0,n) {
22+
int cnt =0;
23+
FOR(j,0,m){
24+
if(a[i][j]=='.' || a[i][j]=='P') cnt++;
25+
}
26+
if(cnt==m) {
27+
FOR(j,0,m) a[i][j] = 'P';
28+
}
29+
}
30+
FOR(i,0,m) {
31+
int cnt =0;
32+
FOR(j,0,n){
33+
if(a[j][i]=='.' || a[j][i] =='P') cnt++;
34+
}
35+
if(cnt==n) {
36+
FOR(j,0,n) a[j][i] = 'P';
37+
}
38+
}
39+
FOR(i,0,n){
40+
int cnt = 0;
41+
FOR(j,0,m){
42+
if(a[i][j]=='P') cnt++;
43+
}
44+
if(cnt==m) continue;
45+
FOR(j,0,m) {
46+
if(a[i][j]=='P') continue;
47+
cout<<a[i][j];
48+
}
49+
cout<<"\n";
50+
}
51+
}
52+
}

axa.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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=1; //cin>>t;
16+
while(t--){
17+
int n,k; cin>>n>>k;
18+
bool o[n+1][3];
19+
FOR(i,0,n+1) o[i][1] = o[i][2] = false;
20+
FOR(i,0,k) {
21+
int x,y;
22+
cin>>x>>y;
23+
o[x][y] = 1;
24+
}
25+
LL dp[n+1][3];
26+
dp[0][1] = dp[0][2] = 0;
27+
FOR(i,1,n+1){
28+
dp[i][1] = dp[i-1][1] + ( o[i][1] ? 1 + dp[i-1][1] : 1);
29+
dp[i][2] = dp[i-1][2] + ( o[i][2] ? 1 + dp[i-1][2] : 1);
30+
}
31+
if(dp[n][1]<dp[n][2]) cout<<"First";
32+
else if(dp[n][1]>dp[n][2]) cout<<"Second";
33+
else cout<<"Draw";
34+
}
35+
}

bca.cpp

+24
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 \
5+
ios_base::sync_with_stdio(0); \
6+
cin.tie(0)
7+
#define LL long long
8+
#define mod 998244353
9+
#define FOR(i, j, k) for (int i = j; i < k; i++)
10+
#define ROF(i, j, k) for (int i = j; i >= k; i--)
11+
12+
const long long INF = 1e18;
13+
const long long MAX = 1e5 + 10;
14+
15+
int main()
16+
{
17+
fastio;
18+
int t = 1; // cin>>t;
19+
while (t--)
20+
{
21+
22+
}
23+
}
24+

check.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# g++ wo.cpp
99
# ./a.out < in.txt > sol.txt
1010
g++ $1
11-
./a.out < input.txt # > out.txt
11+
./a.out < input.txt > out.txt
1212

1313
# if [[ $(diff sol.txt out.txt ) ]]; then
1414
# echo ***********************DIFFERENT ANSWER***********************

gpp.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define fastio \
5+
ios_base::sync_with_stdio(0); \
6+
cin.tie(0)
7+
#define LL long long
8+
#define mod 1000000007
9+
#define all(v) v.begin(), v.end()
10+
#define pr(v) pair<v, v>
11+
#define pb push_back
12+
#define FOR(i, j, k) for (auto i = j; i < k; i++)
13+
#define ROF(i, j, k) for (auto i = j; i >= k; i--)
14+
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
15+
#define time__(d) for (long blockTime = 0; (blockTime == 0 ? (blockTime = clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
16+
17+
const long long INF = 1e18;
18+
const long long MAX = 2e5 + 10;
19+
20+
vector<int> adj[MAX];
21+
vector<bool> vis(MAX, false);
22+
stack<int> st;
23+
void dfs(int u)
24+
{
25+
vis[u] = 1;
26+
for (auto v : adj[u])
27+
{
28+
if (vis[v])
29+
continue;
30+
dfs(v);
31+
}
32+
st.push(u);
33+
}
34+
int main()
35+
{
36+
fastio;
37+
int t = 1; //cin>>t;
38+
while (t--)
39+
{
40+
int n, m;
41+
cin >> n >> m;
42+
FOR(i, 0, m)
43+
{
44+
int x, y;
45+
cin >> x >> y;
46+
adj[x].push_back(y);
47+
}
48+
int s, e;
49+
cin >> s >> e;
50+
dfs(s);
51+
vector<LL> dp(MAX, 0), l;
52+
dp[e] = 1;
53+
while (!st.empty())
54+
{
55+
l.push_back(st.top());
56+
st.pop();
57+
}
58+
for (int i = l.size() - 1; i >= 0; i--)
59+
{
60+
for (int j = 0; j < adj[l[i]].size(); j++)
61+
{
62+
dp[l[i]] = (dp[l[i]] + dp[adj[l[i]][j]])%mod;
63+
}
64+
}
65+
cout << dp[s] << "\n";
66+
}
67+
}

hid.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 1000000007
7+
#define all(v) v.begin(),v.end()
8+
#define FOR(i, j, k) for (auto i=j ; i<k ; i++)
9+
#define ROF(i, j, k) for (auto i=j ; i>=k ; i--)
10+
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
11+
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
12+
13+
const long long INF = 1e18;
14+
const long long MAX = 1e5+10;
15+
int main(){
16+
fastio;
17+
int t=1;// cin>>t;
18+
while(t--){
19+
int n,m; cin>>n>>m;
20+
int a[n+1][m+1];
21+
FOR(i,1,n+1) FOR(j,1,m+1) cin>>a[i][j];
22+
int x,y; cin>>x>>y;
23+
vector<vector<int>>dp(n+1,vector<int>(m+1,INT_MAX));
24+
dp[0][1] = 0;
25+
FOR(i,1,n+1) dp[i][1] = dp[i-1][1] + a[i][1];
26+
FOR(i,2,n+1)
27+
FOR(j,2,m+1)
28+
dp[i][j] = min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]}) + a[i][j];
29+
30+
cout<<dp[x+1][y+1];
31+
}
32+
}

input.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
1
2-
4
1+
3
2+
2 3 2
3+

0 commit comments

Comments
 (0)