Skip to content

Commit

Permalink
BOJ 1013 timeout : need new algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
namaek2 committed Jan 10, 2024
1 parent 12c1e72 commit 9a9ee3f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"files.associations": {
"iostream": "cpp"
"iostream": "cpp",
"ostream": "cpp"
}
}
82 changes: 82 additions & 0 deletions BOJ/BOJ 1013W.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <iostream>
#include <string>

using namespace std;

bool func0(string s, int num) {
if (s[num] != '1') {
return false;
}
return true;
}

int func1(string s, int num) {
if (s[num] != '0' || s[num + 1] != '0') {
return -1;
}

for (int i = num + 2; i < s.length(); i++) {
if (s[i] != '0') {
num = i;
break;
}
}

int c = 0;
for (int i = num; i < s.length(); i++) {
if (s[i] != '1') {
if (s[i + 1] == '0') {
return i - 2;
} else if (s[i + 1] == '1') {
return i - 1;
}
return -1;
}
c++;
num = i;
}

if (c == 0)
return -1;
else
return num;
}

bool func(string s) {
for (int i = 0; i < s.length(); ++i) {
int num;
if (s[i] == '0') {
if (!func0(s, i + 1)) {
return false;
}

++i;
} else if (s[i] == '1') {
num = func1(s, i + 1);
if (num == -1) {
return false;
}
i = num;
}
}
return true;
}

int main(void) {
int m;

scanf("%d", &m);

for (int i = 0; i < m; ++i) {
string s;
cin >> s;

if (func(s)) {
printf("YES\n");
} else {
printf("NO\n");
}
}

return 0;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion DreamHack/rev-basic-3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(void) {

for (int i = 0; i < 24; i++){
int k = (i ^ (arr[i] - 2 * i));
cout << (char)k << " ";
cout << (char)k;
}

return 0;
Expand Down

0 comments on commit 9a9ee3f

Please sign in to comment.