-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BOJ 1013 timeout : need new algorithm
- Loading branch information
Showing
5 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"files.associations": { | ||
"iostream": "cpp" | ||
"iostream": "cpp", | ||
"ostream": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters