1. #include <cstdio>
2. #include <iostream>
3. #include <complex>
4. #include <vector>
5. #include <utility>
6. #include <algorithm>
7. #include <cassert>
8. #include <queue>
9. #include <numeric>
10. using namespace std;
11.
12. #define rep(i, n) for (int i = 0; i < (int)(n); i++)
13.
14. enum { TOP, FRONT, RIGHT, BACK, LEFT, BOTTOM };
15. #define ROTATE_X TOP, FRONT, BOTTOM, BACK
16. #define ROTATE_Y TOP, RIGHT, BOTTOM, LEFT
17.
18. void rotate(vector<int> &p, int a, int b, int c, int d) {
19. swap(p[a], p[b]); swap(p[b], p[c]); swap(p[c], p[d]);
20. }
21.
22. bool hoge(int t1, int t2, int s) {
23. return t1 + t2 > s - t1 - t2;
24. }
25.
26. bool can(vector<int> T) {
27. if (0 > *min_element(T.begin(), T.end())) return false;
28.
29. int S = accumulate(T.begin(), T.end(), 0);
30. return
31. !hoge(T[BOTTOM], T[TOP], S) &&
32. !hoge(T[FRONT], T[BACK], S + 1) &&
33. !hoge(T[LEFT], T[RIGHT], S + 1);
34. }
35.
36. string solve(vector<int> T) {
37. if (!can(T)) return "X";
38.
39. string ans = "";
40. while (0 < *max_element(T.begin(), T.end())) {
41. {
42. vector<int> t(T);
43. rotate(t, ROTATE_X);
44. t[BOTTOM]--;
45. if (can(t)) {
46. ans += 'E';
47. T = t;
48. continue;
49. }
50. }
51. {
52. vector<int> t(T);
53. rotate(t, ROTATE_Y);
54. t[BOTTOM]--;
55. if (can(t)) {
56. ans += 'N';
57. T = t;
58. continue;
59. }
60. }
61. {
62. vector<int> t(T);
63. rep (i, 3) rotate(t, ROTATE_Y);
64. t[BOTTOM]--;
65. if (can(t)) {
66. ans += 'S';
67. T = t;
68. continue;
69. }
70. }
71. {
72. vector<int> t(T);
73. rep (i, 3) rotate(t, ROTATE_X);
74. t[BOTTOM]--;
75. if (can(t)) {
76. ans += 'W';
77. T = t;
78. continue;
79. }
80. }
81. }
82. return ans;
83. }
84.
85. int main() {
86. for (;;) {
87. vector<int> T(6);
88. rep (i, 6) scanf("%d", &T[i]);
89. if (0 == *max_element(T.begin(), T.end())) return 0;
90.
91. string ans = "X";
92. do {
93. string tmp = solve(T);
94. ans = min(ans, tmp);
95. } while (next_permutation(T.begin(), T.end()));
96.
97. int P, Q;
98. scanf("%d%d", &P, &Q);
99. if (ans == "X") cout << "impossible" << endl;
100. else cout << ans.substr(P - 1, Q - P + 1) << endl;
101. }
102. }
103.
Success #stdin #stdout 0.03s 3484KB
stdin
1 1 1 1 1 1
1 6
1 1 1 1 1 1
4 5
0 0 0 0 0 2
1 2
0 0 2 2 2 4
5 9
1 2 3 4 5 6
15 16
0 1 2 3 5 9
13 16
2 13 22 27 31 91
100 170
0 0 0 0 0 0
stdout
EEENEE
NE
impossible
NSSNW
EN
EWNS
SNSNSNSNSNSNSNSNSNSNSNSSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNWEWE