Skip to content

Commit 97318e3

Browse files
committed
abc 276
1 parent 738c3c2 commit 97318e3

File tree

7 files changed

+421
-0
lines changed

7 files changed

+421
-0
lines changed

Atcoder/ABC/abc276_A-Rightmost.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
string s;
22+
cin>>s;
23+
int ans=-1;
24+
for(int i=0;i<s.size();i++){
25+
if(s[i]=='a'){
26+
ans=i+1;
27+
}
28+
}
29+
cout<<ans<<endl;
30+
return 0;
31+
}
32+
int main()
33+
{
34+
long long testCase;
35+
testCase=1;
36+
while(testCase--){
37+
solve();
38+
}
39+
return 0;
40+
}
41+
/* -----------------END OF PROGRAM --------------------*/
42+
/*
43+
* stuff you should look before submission
44+
* constraint and time limit
45+
* int overflow
46+
* special test case (n=0||n=1||n=2)
47+
* don't get stuck on one approach if you get wrong answer
48+
*/
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
/* ascii value
10+
A=65,Z=90,a=97,z=122
11+
*/
12+
13+
// Techniques :
14+
// divide into cases, brute force, pattern finding
15+
// sort, greedy, binary search, two pointer
16+
// transform into graph
17+
18+
int solve()
19+
{
20+
int n, m;
21+
cin >> n >> m;
22+
vector<vector<int>> v(n + 1);
23+
for (int i = 0; i < m; i++)
24+
{
25+
int a, b;
26+
cin >> a >> b;
27+
v[a].push_back(b);
28+
v[b].push_back(a);
29+
}
30+
for (int i = 1; i <= n; i++)
31+
{
32+
cout << v[i].size() << " ";
33+
sort(v[i].begin(), v[i].end());
34+
if (v[i].size())
35+
{
36+
for (auto x : v[i])
37+
{
38+
cout << x << " ";
39+
}
40+
}
41+
cout << endl;
42+
}
43+
return 0;
44+
}
45+
int main()
46+
{
47+
long long testCase;
48+
testCase = 1;
49+
50+
while (testCase--)
51+
{
52+
solve();
53+
}
54+
return 0;
55+
}
56+
/* -----------------END OF PROGRAM --------------------*/
57+
/*
58+
* stuff you should look before submission
59+
* constraint and time limit
60+
* int overflow
61+
* special test case (n=0||n=1||n=2)
62+
* don't get stuck on one approach if you get wrong answer
63+
*/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
int n;
22+
cin>>n;
23+
vector<int> v(n);
24+
for(auto &x:v){
25+
cin>>x;
26+
}
27+
prev_permutation(v.begin(),v.end());
28+
for(auto x:v){
29+
cout<<x<<" ";
30+
}
31+
return 0;
32+
}
33+
int main()
34+
{
35+
long long testCase;
36+
testCase = 1;
37+
38+
while(testCase--){
39+
solve();
40+
}
41+
return 0;
42+
}
43+
/* -----------------END OF PROGRAM --------------------*/
44+
/*
45+
* stuff you should look before submission
46+
* constraint and time limit
47+
* int overflow
48+
* special test case (n=0||n=1||n=2)
49+
* don't get stuck on one approach if you get wrong answer
50+
*/
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
int n;
22+
cin>>n;
23+
vector<int> v(n);
24+
for(auto& x:v){
25+
cin>>x;
26+
}
27+
int hcf=v[0];
28+
for(int i=1;i<n;i++){
29+
hcf=__gcd(hcf,v[i]);
30+
}
31+
int operation=0;
32+
for(int i=0;i<n;i++){
33+
if(v[i]%hcf){
34+
cout<<-1<<endl;
35+
return 0;
36+
}
37+
else{
38+
int d=v[i]/hcf;
39+
while(d%2==0){
40+
d/=2;
41+
operation++;
42+
}
43+
while(d%3==0){
44+
d/=3;
45+
operation++;
46+
}
47+
if(d!=1){
48+
cout<<-1<<endl;
49+
return 0;
50+
}
51+
}
52+
}
53+
cout<<operation<<endl;
54+
return 0;
55+
}
56+
int main()
57+
{
58+
long long testCase;
59+
testCase = 1;
60+
61+
while(testCase--){
62+
solve();
63+
}
64+
return 0;
65+
}
66+
/* -----------------END OF PROGRAM --------------------*/
67+
/*
68+
* stuff you should look before submission
69+
* constraint and time limit
70+
* int overflow
71+
* special test case (n=0||n=1||n=2)
72+
* don't get stuck on one approach if you get wrong answer
73+
*/
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
/* ascii value
10+
A=65,Z=90,a=97,z=122
11+
*/
12+
13+
// Techniques :
14+
// divide into cases, brute force, pattern finding
15+
// sort, greedy, binary search, two pointer
16+
// transform into graph
17+
int flag=0;
18+
int h,w;
19+
vector<vector<char>> grid;
20+
vector<vector<bool>> check;
21+
22+
void dfs(int i,int j,int count){
23+
if(i<0 || j<0 || i>=h || j>=w){
24+
return;
25+
}
26+
if(check[i][j]==true){
27+
return;
28+
}
29+
if(grid[i][j]=='#'){
30+
return;
31+
}
32+
if(grid[i][j]=='S' && count>0){
33+
flag+=(count>=4);
34+
return;
35+
}
36+
check[i][j]=true;
37+
dfs(i+1,j,count+1);
38+
dfs(i-1,j,count+1);
39+
dfs(i,j+1,count+1);
40+
dfs(i,j-1,count+1);
41+
42+
}
43+
44+
int solve()
45+
{
46+
cin>>h>>w;
47+
int intialI = 0, intialJ = 0;
48+
49+
grid.resize(h,vector<char>(w));
50+
check.resize(h,vector<bool>(w,false));
51+
52+
for(int i=0;i<h;i++){
53+
for(int j=0;j<w;j++){
54+
cin>>grid[i][j];
55+
if(grid[i][j]=='S'){
56+
intialI = i;
57+
intialJ = j;
58+
}
59+
}
60+
}
61+
dfs(intialI+1,intialJ,1);
62+
dfs(intialI-1,intialJ,1);
63+
dfs(intialI,intialJ+1,1);
64+
dfs(intialI,intialJ-1,1);
65+
if(flag){
66+
cout<<"Yes"<<endl;
67+
}
68+
else{
69+
cout<<"No"<<endl;
70+
}
71+
return 0;
72+
}
73+
int main()
74+
{
75+
long long testCase;
76+
testCase = 1;
77+
78+
while (testCase--)
79+
{
80+
solve();
81+
}
82+
return 0;
83+
}
84+
/* -----------------END OF PROGRAM --------------------*/
85+
/*
86+
* stuff you should look before submission
87+
* constraint and time limit
88+
* int overflow
89+
* special test case (n=0||n=1||n=2)
90+
* don't get stuck on one approach if you get wrong answer
91+
*/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
int n;
22+
cin>>n;
23+
long long sum=0;
24+
for(int i=0;i<n;i++){
25+
long long temp;
26+
cin>>temp;
27+
sum+=temp;
28+
}
29+
cout<<abs(sum)<<endl;
30+
return 0;
31+
}
32+
int main()
33+
{
34+
long long testCase;
35+
cin>>testCase;
36+
while(testCase--){
37+
solve();
38+
}
39+
return 0;
40+
}
41+
/* -----------------END OF PROGRAM --------------------*/
42+
/*
43+
* stuff you should look before submission
44+
* constraint and time limit
45+
* int overflow
46+
* special test case (n=0||n=1||n=2)
47+
* don't get stuck on one approach if you get wrong answer
48+
*/

0 commit comments

Comments
 (0)