CSES - Datatähti 2023 loppu - Results
Submission details
Task:Ruudukko
Sender:stpn129
Submission time:2023-01-21 16:31:48 +0200
Language:C++20
Status:READY
Result:11
Feedback
groupverdictscore
#1ACCEPTED11
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 2, 3details
#4ACCEPTED0.00 s1, 2, 3details
#5ACCEPTED0.00 s1, 2, 3details
#6ACCEPTED0.00 s1, 2, 3details
#7ACCEPTED0.00 s1, 2, 3details
#8ACCEPTED0.00 s1, 2, 3details
#9ACCEPTED0.00 s1, 2, 3details
#10ACCEPTED0.00 s1, 2, 3details
#11ACCEPTED0.00 s1, 2, 3details
#12ACCEPTED0.00 s1, 2, 3details
#13ACCEPTED0.00 s1, 2, 3details
#14ACCEPTED0.00 s1, 2, 3details
#15ACCEPTED0.00 s1, 2, 3details
#16ACCEPTED0.00 s1, 2, 3details
#17ACCEPTED0.00 s2, 3details
#18ACCEPTED0.00 s2, 3details
#19ACCEPTED0.00 s2, 3details
#200.00 s2, 3details
#21ACCEPTED0.00 s2, 3details
#22ACCEPTED0.00 s2, 3details
#23ACCEPTED0.00 s2, 3details
#240.00 s2, 3details
#250.03 s3details
#260.03 s3details
#270.03 s3details
#280.03 s3details
#290.03 s3details
#300.03 s3details
#310.03 s3details
#320.03 s3details
#330.03 s3details
#340.03 s3details
#350.03 s3details
#360.03 s3details

Code

#include<bits/stdc++.h>
 
 
using namespace std;
 
void init_code(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
 
bool cmp (pair<int, int> a, pair<int, int> b) {
   return a.second < b.second;
}
 
const int mod = 1e9 + 7;
 
vector<pair<int, int>> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
 
int cycle = 0;
void dfs(pair<int, int> v, pair<int, int> p, vector<vector<int>>& res, vector<vector<int>>& used, int n, int m) {
   //cout << v.first << ' ' << v.second << ' ' << used[v.first][v.second]  <<'\n';
   if (used[v.first][v.second] == 1) {
      cycle = 1;
      return;
   }
 
   used[v.first][v.second] = 1;
   
   for (auto mv : moves) {
      int x = v.first + mv.first, y = v.second + mv.second;
      if (x >= 0 && x < n && y >= 0 && y < m && res[x][y] == 0 && !(x == p.first && y == p.second)) {
         dfs({x, y}, v, res, used, n, m);
      }
   }
 
}
 
 
void solve() {
   int n, m;
   cin >> n >> m;

   if (n <= 4 && m <= 4) {
      vector<vector<int>> res (n, vector<int> (m));
      vector<vector<int>> used (n, vector<int> (m));
      int mn = 1 << (n * m);
      for (int i = 0; i < mn; ++i) {
         cycle = 0;
         fill(res.begin(), res.end(), vector<int> (m, 0));
         fill(used.begin(), used.end(), vector<int> (m, 0));
         int x = i, cnt = 0;
         while (x > 0) {
            int t = x % 2;
            if (t) {
               int xcoord = cnt / m;
               int ycoord = cnt % m;
               res[xcoord][ycoord] = 1; 
            }
            x >>= 1;
            cnt++;
         }
    
         int sx = 0, sy = 0;
         for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
               if (res[i][j] == 0) {
                  sx = i; sy = j;
                  break;
               }
            }
         }
    
         //cout << sx << ' ' << sy << '\n';
         if (res[sx][sy] == 1) {
            continue;
         } else {
            dfs({sx, sy}, {-1, -1}, res, used, n, m);
            //cout << cycle;
            int check = !cycle;
            for (int i = 0; i < n; ++i) {
               for (int j = 0; j < m; ++j) {
                  if (res[i][j] == 0 && used[i][j] == 0) {
                     check = 0;
                  }
                  if (res[i][j] == 1) {
                     for (auto mv : moves) {
                        int x = i + mv.first, y = j + mv.second;
                        if (x >= 0 && x < n && y >= 0 && y < m && res[x][y] == 1) {
                           check = 0;              
                        }
                     }
                  }
                  if (check == 0) {
                     break;
                  }
               }
            }
    
            if (check == 1) {
               for (int i = 0; i < n; ++i) {
                  for (int j = 0; j < m; ++j) {
                     if (res[i][j] == 0) cout << '.';
                     else cout << '#';
                  } 
                  cout << '\n';
               }       
               cout << '\n';
               return;
            }
         }
      }
   } else {
      vector<vector<int>> res (n, vector<int> (m));
      
      if (m == 1) {
         ;
      }

      if (m == 2) {
         int cnt = 0;
         vector<int> a = {0, 1};
         vector<int> b = {1, 0};
         for (int i = 0; i < n; ++i) {
            if (i % 2 != 0) {
               for (int j = 0; j < m; ++j) {
                  res[i][j] = 0;
               }
            } else {
               if (cnt % 2 == 0) {
                  for (int j = 0; j < m; ++j) {
                     res[i][j] = a[j];
                  }
               } else {
                  for (int j = 0; j < m; ++j) {
                     res[i][j] = b[j];
                  }
               }
               cnt++;
            }
         }
      }

      if (m == 3) {
         vector<int> a = {1, 0, 0};
         vector<int> b = {0, 0, 1};
         for (int i = 0; i < n; ++i) {
            if (i % 2 == 0) {
               for (int j = 0; j < m; ++j) {
                  res[i][j] = a[j];
               }
            } else {
               for (int j = 0; j < m; ++j) {
                  res[i][j] = b[j];
               }
            }
         }
      }

      if (m == 4) {
         vector<int> a = {0, 0, 1, 0};
         vector<int> b = {0, 1, 0, 0};
         vector<int> c = {0, 0, 1, 0};
         vector<int> d = {1, 0, 0, 0};
         
         for (int i = 0; i < n; ++i) {
            if (i % 4 == 0) {
               for (int j = 0; j < m; ++j) {
                  res[i][j] = a[j];
               }
            } 
            if (i % 4 == 1) {
               for (int j = 0; j < m; ++j) {
                  res[i][j] = b[j];
               }
            }
            if (i % 4 == 2) {
               for (int j = 0; j < m; ++j) {
                  res[i][j] = c[j];
               }
            }
            if (i % 4 == 3) {
               for (int j = 0; j < m; ++j) {
                  res[i][j] = d[j];
               }
            }
         }
      }

      for (int i = 0; i < n; ++i) {
         for (int j = 0; j < m; ++j) {
            if (res[i][j] == 0) cout << '.';
            else cout << '#';
         }
         cout << '\n';
      }
   }
}
 
signed main() {
   init_code();
   int t = 1; 
   //cin >> t;
   while(t--){
      solve();
   }
   return 0;
}
 
/*
cubbli-guest@dx5-cs-b221-09:~$ cd Code
cubbli-guest@dx5-cs-b221-09:~/Code$ ls
code  code.cpp  input.txt  output.txt
cubbli-guest@dx5-cs-b221-09:~/Code$ g++ code.cpp -o code
cubbli-guest@dx5-cs-b221-09:~/Code$ ./code
Segmentation fault (core dumped)
cubbli-guest@dx5-cs-b221-09:~/Code$ 
*/

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
1 1

correct output
.

user output
.

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
1 2

correct output
..

user output
..

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
1 3

correct output
...

user output
...

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
1 4

correct output
....

user output
....

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
2 1

correct output
.
.

user output
.
.

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
2 2

correct output
.#
..

user output
#.
..

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
2 3

correct output
.#.
...

user output
.#.
...

Test 8

Group: 1, 2, 3

Verdict: ACCEPTED

input
2 4

correct output
.#.#
....

user output
#.#.
....

Test 9

Group: 1, 2, 3

Verdict: ACCEPTED

input
3 1

correct output
.
.
.

user output
.
.
.

Test 10

Group: 1, 2, 3

Verdict: ACCEPTED

input
3 2

correct output
.#
..
.#

user output
..
#.
..

Test 11

Group: 1, 2, 3

Verdict: ACCEPTED

input
3 3

correct output
.#.
...
.#.

user output
#..
.#.
...

Test 12

Group: 1, 2, 3

Verdict: ACCEPTED

input
3 4

correct output
.#.#
....
.#.#

user output
...#
#.#.
....

Test 13

Group: 1, 2, 3

Verdict: ACCEPTED

input
4 1

correct output
.
.
.
.

user output
.
.
.
.

Test 14

Group: 1, 2, 3

Verdict: ACCEPTED

input
4 2

correct output
..
.#
..
#.

user output
#.
..
#.
..

Test 15

Group: 1, 2, 3

Verdict: ACCEPTED

input
4 3

correct output
...
.#.
..#
#..

user output
..#
#..
.#.
...

Test 16

Group: 1, 2, 3

Verdict: ACCEPTED

input
4 4

correct output
....
.#.#
..#.
#...

user output
...#
.#..
#.#.
....

Test 17

Group: 2, 3

Verdict: ACCEPTED

input
999 1

correct output
.
.
.
.
.
...

user output
.
.
.
.
.
...

Test 18

Group: 2, 3

Verdict: ACCEPTED

input
999 2

correct output
.#
..
.#
..
#.
...

user output
.#
..
#.
..
.#
...

Test 19

Group: 2, 3

Verdict: ACCEPTED

input
999 3

correct output
.#.
...
.#.
..#
#..
...

user output
#..
..#
#..
..#
#..
...

Test 20

Group: 2, 3

Verdict:

input
999 4

correct output
.#.#
....
.#.#
..#.
#...
...

user output
..#.
.#..
..#.
#...
..#.
...

Test 21

Group: 2, 3

Verdict: ACCEPTED

input
1000 1

correct output
.
.
.
.
.
...

user output
.
.
.
.
.
...

Test 22

Group: 2, 3

Verdict: ACCEPTED

input
1000 2

correct output
..
.#
..
#.
..
...

user output
.#
..
#.
..
.#
...

Test 23

Group: 2, 3

Verdict: ACCEPTED

input
1000 3

correct output
...
.#.
..#
#..
..#
...

user output
#..
..#
#..
..#
#..
...

Test 24

Group: 2, 3

Verdict:

input
1000 4

correct output
....
.#.#
..#.
#...
..#.
...

user output
..#.
.#..
..#.
#...
..#.
...

Test 25

Group: 3

Verdict:

input
999 995

correct output
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...

user output
.................................

Test 26

Group: 3

Verdict:

input
999 996

correct output
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...

user output
.................................

Test 27

Group: 3

Verdict:

input
999 997

correct output
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...

user output
.................................

Test 28

Group: 3

Verdict:

input
999 998

correct output
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...

user output
.................................

Test 29

Group: 3

Verdict:

input
999 999

correct output
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...

user output
.................................

Test 30

Group: 3

Verdict:

input
999 1000

correct output
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...

user output
.................................

Test 31

Group: 3

Verdict:

input
1000 995

correct output
.................................

user output
.................................

Test 32

Group: 3

Verdict:

input
1000 996

correct output
.................................

user output
.................................

Test 33

Group: 3

Verdict:

input
1000 997

correct output
.................................

user output
.................................

Test 34

Group: 3

Verdict:

input
1000 998

correct output
.................................

user output
.................................

Test 35

Group: 3

Verdict:

input
1000 999

correct output
.................................

user output
.................................

Test 36

Group: 3

Verdict:

input
1000 1000

correct output
.................................

user output
.................................