Skip to content

Commit 6b2165d

Browse files
committed
updated
1 parent d4d2719 commit 6b2165d

File tree

6 files changed

+63
-60
lines changed

6 files changed

+63
-60
lines changed

CPP.sublime-build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[
44
"bash",
55
"-c",
6-
"g++ -std=gnu++17 -DLOCAL -Wall -fsanitize=undefined -D_GLIBCXX_DEBUG '${file}' -o '${file_path}/${file_base_name}' && timeout 10s '${file_path}/${file_base_name}'<in.txt>out.txt"
6+
"g++ -std=gnu++17 -O2 -DLOCAL -Wall '${file}' -o '${file_path}/${file_base_name}' && timeout 3s '${file_path}/${file_base_name}'<in.txt>out.txt"
77
],
88
"selector": "source.c, source.c++"
99
}

code.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,31 @@ int tc = 1;
2929
#endif
3030

3131
void solve() {
32-
32+
string s;
33+
cin >> s;
34+
set<char> st;
35+
for (auto &it : s) {
36+
st.insert(it);
37+
}
38+
if (sz(st) == 1) {
39+
cout << "NO\n";
40+
} else {
41+
for (int i = 0; i < sz(s) - 1; i++) {
42+
if (s[i] != s[i + 1]) {
43+
swap(s[i], s[i + 1]);
44+
break;
45+
}
46+
}
47+
cout << "YES\n";
48+
cout << s << '\n';
49+
}
3350
}
3451

3552
int main() {
3653
unsyncIO;
3754

3855
int t = 1;
39-
//cin >> t;
56+
cin >> t;
4057
while (t--) {
4158
solve();
4259
}

code.cpp:tests

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"correct_answers":
4+
[
5+
"YES\nforcodesec\nNO\nYES\nxxyxx\nYES\noc\nNO\nYES\nundertale\nYES\nthtsiwm\nNO"
6+
],
7+
"test": "8\ncodeforces\naaaaa\nxxxxy\nco\nd\nnutdealer\nmwistht\nhhhhhhhhhh\n"
8+
}
9+
]

debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
* https://g...content-available-to-author-only...b.com/SansPapyrus683/61b65d4d7ec223b48ebf5c3bb382ba8d
1919
*/
2020

21-
#include <bits/stdc++.h>
22-
using namespace std;
21+
// #include <bits/stdc++.h>
22+
// using namespace std;
2323

2424
template <typename T1, typename T2>
2525
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {

precompiled header.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//sudo g++ -std=gnu++17 -O2 -Wall -DLOCAL /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h

sol.cpp

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,44 @@
1-
#include <iostream>
2-
#include <vector>
1+
#include <bits/stdc++.h>
32

4-
using namespace std;
5-
6-
void topologicalSortUtil(vector<vector<int>>& graph, vector<int>& indegree, vector<int>& path, vector<bool>& visited) {
7-
bool flag = false;
8-
9-
for (int i = 0; i < graph.size(); ++i) {
10-
if (indegree[i] == 0 && !visited[i]) {
11-
for (int j = 0; j < graph[i].size(); ++j) {
12-
indegree[graph[i][j]]--;
13-
}
14-
path.push_back(i);
15-
visited[i] = true;
16-
topologicalSortUtil(graph, indegree, path, visited);
3+
#define sqr(x) (x) * (x)
4+
#define sz(x) (int)x.size()
5+
#define all(x) (x).begin(),(x).end()
6+
#define rall(x) (x).rbegin(),(x).rend()
7+
#define prec(x) fixed<<setprecision(x)
8+
#define testcase cout << "Case " << tc++ << ": "
9+
#define unsyncIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
1710

18-
visited[i] = false;
19-
path.pop_back();
20-
for (int j = 0; j < graph[i].size(); ++j) {
21-
indegree[graph[i][j]]++;
22-
}
11+
using namespace std;
2312

24-
flag = true;
25-
}
26-
}
13+
using ll = long long;
14+
using ld = long double;
15+
using ull = unsigned long long;
16+
template <typename T>
17+
using minHeap = priority_queue<T, vector<T>, greater<T>>;
2718

28-
if (!flag) {
29-
for (int i = 0; i < path.size(); ++i) {
30-
cout << path[i] << " ";
31-
}
32-
cout << endl;
33-
}
34-
}
19+
const ld PI = acos(-1.0);
20+
const ll MOD = 1e9 + 7;
21+
const ld EPS = 1e-9;
22+
const ll N = 2e5 + 5;
23+
int tc = 1;
3524

36-
void allTopologicalSorts(vector<vector<int>>& graph, int V) {
37-
vector<int> indegree(V, 0);
38-
vector<bool> visited(V, false);
39-
vector<int> path;
25+
#ifdef LOCAL
26+
#include "debug.h"
27+
#else
28+
#define debug(...)
29+
#endif
4030

41-
for (int i = 0; i < V; ++i) {
42-
for (int j = 0; j < graph[i].size(); ++j) {
43-
indegree[graph[i][j]]++;
44-
}
45-
}
31+
void solve() {
4632

47-
topologicalSortUtil(graph, indegree, path, visited);
4833
}
4934

5035
int main() {
51-
int V, E;
52-
// cout << "Enter the number of vertices and edges: ";
53-
cin >> V >> E;
54-
55-
vector<vector<int>> graph(V);
36+
unsyncIO;
5637

57-
// cout << "Enter the edges (format: from to):" << endl;
58-
for (int i = 0; i < E; ++i) {
59-
int from, to;
60-
cin >> from >> to;
61-
graph[from].push_back(to);
38+
int t = 1;
39+
//cin >> t;
40+
while (t--) {
41+
solve();
6242
}
63-
64-
// cout << "All possible topological sorts are:" << endl;
65-
allTopologicalSorts(graph, V);
66-
6743
return 0;
68-
}
44+
}

0 commit comments

Comments
 (0)