Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 278c396

Browse files
does 1 question 900 rated
1 parent 893f620 commit 278c396

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
// Type definitions
5+
typedef long long ll;
6+
typedef pair<int, int> pii;
7+
typedef pair<ll, ll> pll;
8+
typedef vector<int> vi;
9+
typedef vector<ll> vl;
10+
typedef vector<pii> vpii;
11+
typedef vector<pll> vpll;
12+
typedef vector<vi> vvi;
13+
typedef vector<vl> vvl;
14+
15+
// Macros
16+
#define nline "\n"
17+
#define all(x) (x).begin(), (x).end()
18+
#define rall(x) (x).rbegin(), (x).rend()
19+
#define sz(x) (int)(x).size()
20+
#define pb push_back
21+
#define mp make_pair
22+
#define F first
23+
#define S second
24+
#define forn(i, n) for (int i = 0; i < int(n); i++)
25+
#define forr(i, a, b) for (int i = a; i <= b; i++)
26+
#define ford(i, a, b) for (int i = a; i >= b; i--)
27+
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
28+
29+
// Constants
30+
const int MOD = 1e9 + 7;
31+
const ll INF = 1e18;
32+
const double EPS = 1e-9;
33+
const double PI = acos(-1);
34+
35+
ll mod_add(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
36+
ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
37+
ll mod_mul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }
38+
39+
ll mod_pow(ll base, ll exp, ll m = MOD)
40+
{
41+
ll res = 1;
42+
base %= m;
43+
while (exp > 0)
44+
{
45+
if (exp & 1)
46+
res = mod_mul(res, base, m);
47+
base = mod_mul(base, base, m);
48+
exp >>= 1;
49+
}
50+
return res;
51+
}
52+
53+
ll mod_inv(ll a, ll m = MOD)
54+
{
55+
return mod_pow(a, m - 2, m); // Only works if m is prime
56+
}
57+
58+
ll mod_div(ll a, ll b, ll m = MOD)
59+
{
60+
return mod_mul(a, mod_inv(b, m), m);
61+
}
62+
63+
// Binary exponentiation (for non-modular calculations)
64+
ll binpow(ll base, ll exp)
65+
{
66+
ll res = 1;
67+
while (exp > 0)
68+
{
69+
if (exp & 1)
70+
res *= base;
71+
base *= base;
72+
exp >>= 1;
73+
}
74+
return res;
75+
}
76+
77+
/************/
78+
void solve()
79+
{
80+
int n, k;
81+
cin >> n >> k;
82+
83+
string str;
84+
cin >> str;
85+
86+
string rev = str;
87+
reverse(all(rev));
88+
89+
if (str < rev)
90+
cout << "YES" << nline;
91+
else if (count(all(str), str[0]) == n)
92+
cout << "NO" << nline;
93+
else if (k)
94+
cout << "YES" << nline;
95+
else
96+
cout << "NO" << nline;
97+
}
98+
int main()
99+
{
100+
ios_base::sync_with_stdio(0);
101+
cin.tie(0);
102+
cout.tie(0);
103+
104+
#ifndef ONLINE_JUDGE
105+
freopen("./outputs/input.txt", "r", stdin);
106+
freopen("./outputs/output.txt", "w", stdout);
107+
#endif
108+
109+
int t;
110+
cin >> t;
111+
while (t--)
112+
solve();
113+
114+
return 0;
115+
}
116+
// Explanatie
117+
/* */

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /