Skip to content

Commit 0ae529d

Browse files
authored
Add files via upload
1 parent c36b471 commit 0ae529d

File tree

5 files changed

+231
-0
lines changed

5 files changed

+231
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include<bits/stdc++.h>
2+
#include <ext/pb_ds/tree_policy.hpp>
3+
#include <ext/pb_ds/assoc_container.hpp>
4+
5+
using namespace __gnu_pbds;
6+
using namespace std;
7+
8+
template<typename T>
9+
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
10+
#define ll long long
11+
#define endl '\n'
12+
13+
14+
int main() {
15+
ios::sync_with_stdio(false);
16+
cout.tie(nullptr);
17+
cin.tie(nullptr);
18+
int t;
19+
cin >> t;
20+
while (t--) {
21+
int n, m;
22+
cin >> n >> m;
23+
map<int,int> mp;
24+
for (int i = 0; i < n; ++i) {
25+
int x;
26+
cin >> x;
27+
mp[x%m]++;
28+
}
29+
int cnt = 0;
30+
for (int i = 0; i < m; ++i) {
31+
int rem = i , com = (m-i)%m;
32+
int mn = min(mp[rem] , mp[com]);
33+
if ( mn > 0)
34+
{
35+
cnt++;
36+
mp[rem] -=mn;
37+
mp[com] -=mn;
38+
}
39+
if ( mp[rem] > 0)
40+
{
41+
cnt += ( mp[rem] - 1);
42+
if ( mn == 0)
43+
cnt++;
44+
mp[rem] =0;
45+
}
46+
else if ( mp[com] > 0)
47+
{
48+
cnt += (mp[com] -1);
49+
if ( mn == 0)
50+
cnt++;
51+
mp[com] = 0;
52+
}
53+
mp[com] = mp[rem] = 0;
54+
}
55+
cout << cnt << endl;
56+
}
57+
return 0;
58+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<bits/stdc++.h>
2+
#include <ext/pb_ds/tree_policy.hpp>
3+
#include <ext/pb_ds/assoc_container.hpp>
4+
5+
using namespace __gnu_pbds;
6+
using namespace std;
7+
8+
template<typename T>
9+
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
10+
#define ll long long
11+
#define endl '\n'
12+
13+
14+
int main() {
15+
ios::sync_with_stdio(false);
16+
cout.tie(nullptr);
17+
cin.tie(nullptr);
18+
int t;
19+
cin >> t;
20+
while (t--) {
21+
ll n;
22+
cin >> n;
23+
while (true)
24+
{
25+
ll sum =0;
26+
string s = to_string(n);
27+
for (int i = 0; i < s.size(); ++i) {
28+
sum += ( s[i] - '0');
29+
}
30+
if (__gcd(n,sum) > 1)
31+
{
32+
cout << n << endl;
33+
break;
34+
}
35+
n++;
36+
}
37+
}
38+
return 0;
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<bits/stdc++.h>
2+
#include <ext/pb_ds/tree_policy.hpp>
3+
#include <ext/pb_ds/assoc_container.hpp>
4+
5+
using namespace __gnu_pbds;
6+
using namespace std;
7+
8+
template<typename T>
9+
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
10+
#define ll long long
11+
#define endl '\n'
12+
13+
14+
int main() {
15+
ios::sync_with_stdio(false);
16+
cout.tie(nullptr);
17+
cin.tie(nullptr);
18+
int t;
19+
cin >> t;
20+
while (t--) {
21+
int n;
22+
cin >> n;
23+
deque<int> v = {1,1};
24+
for (int i = 0; i < n-2; ++i) {
25+
v.push_back(0);
26+
}
27+
for (int i = 0; i < n; ++i) {
28+
for (int j = 0; j < n; ++j) {
29+
cout << v[j] << " ";
30+
}
31+
cout << endl;
32+
v.push_back(v.front());
33+
v.pop_front();
34+
}
35+
36+
37+
}
38+
return 0;
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include<bits/stdc++.h>
2+
#include <ext/pb_ds/tree_policy.hpp>
3+
#include <ext/pb_ds/assoc_container.hpp>
4+
5+
using namespace __gnu_pbds;
6+
using namespace std;
7+
8+
template<typename T>
9+
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
10+
#define ll long long
11+
#define endl '\n'
12+
13+
14+
int main() {
15+
ios::sync_with_stdio(false);
16+
cout.tie(nullptr);
17+
cin.tie(nullptr);
18+
int t;
19+
cin >> t;
20+
while (t--) {
21+
int n;
22+
cin >> n;
23+
int a[n];
24+
for (int i = 0; i < n; ++i) {
25+
cin >> a[i];
26+
}
27+
int idx = -1;
28+
int mx = *max_element(a,a+n);
29+
for (int i = 0; i < n; ++i) {
30+
if ( a[i] == mx)
31+
{
32+
if ( i && a[i-1] < a[i])
33+
idx = i;
34+
if ( i+1 < n && a[i+1] < a[i])
35+
idx = i;
36+
}
37+
}
38+
if ( idx == -1 )
39+
cout << -1 << endl;
40+
else
41+
cout << idx+1 << endl;
42+
43+
}
44+
return 0;
45+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include<bits/stdc++.h>
2+
#include <ext/pb_ds/tree_policy.hpp>
3+
#include <ext/pb_ds/assoc_container.hpp>
4+
5+
using namespace __gnu_pbds;
6+
using namespace std;
7+
8+
template<typename T>
9+
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
10+
#define ll long long
11+
#define endl '\n'
12+
13+
14+
int main() {
15+
ios::sync_with_stdio(false);
16+
cout.tie(nullptr);
17+
cin.tie(nullptr);
18+
int n,m;
19+
cin >> n >> m;
20+
int a[n][m],b[n][m];
21+
for (int i = 0; i < n; ++i) {
22+
for (int j = 0; j < m; ++j) {
23+
cin >> a[i][j];
24+
b[i][j] =0;
25+
}
26+
}
27+
vector<pair<int,int>> v;
28+
for (int i = 0; i < n-1; ++i) {
29+
for (int j = 0; j < m-1; ++j) {
30+
if ( a[i][j] + a[i+1][j] + a[i][j+1]+a[i+1][j+1] == 4)
31+
{
32+
v.push_back({i+1,j+1});
33+
b[i][j] = b[i+1][j] = b[i][j+1]=b[i+1][j+1] = 1;
34+
}
35+
}
36+
}
37+
for (int i = 0; i < n; ++i) {
38+
for (int j = 0; j < m; ++j) {
39+
if ( a[i][j] != b[i][j])
40+
{
41+
cout << -1 << endl;
42+
return 0;
43+
}
44+
}
45+
}
46+
cout << v.size() << endl;
47+
for(auto it : v)
48+
cout << it.first << " " << it.second << endl;
49+
return 0;
50+
}

0 commit comments

Comments
 (0)