fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef long double dbl;
  7. typedef vector <int> vi;
  8. typedef pair <int, int> pii;
  9.  
  10. int const N = 1002;
  11. int const MD = 1000000007;
  12.  
  13. #define FOR(i, a, b) for (int (i) = (a); (i) <= (b); ++(i))
  14. #define RFOR(i, a, b) for (int (i) = (a); (i) >= (b); --(i))
  15. #define REP(i, n) FOR(i, 0, n - 1)
  16. #define pb push_back
  17. #define mp make_pair
  18. #define X first
  19. #define Y second
  20. #define sz(v) int(v.size())
  21.  
  22. int res[N][N];
  23.  
  24. int main() {
  25. int N, M, K;
  26. scanf("%d%d%d", &N, &M, &K);
  27. vector <pii> parts;
  28. FOR (i, 1, N) {
  29. FOR (j, 1, M) {
  30. if (i & 1) {
  31. parts.pb(mp(i, j));
  32. } else {
  33. parts.pb(mp(i, M - j + 1));
  34. }
  35. }
  36. }
  37. int X = (N * M) / K;
  38. int ptr = 0;
  39. FOR (it, 1, (N * M) % K) {
  40. FOR (i, 1, X + 1) {
  41. res[parts[ptr].X][parts[ptr].Y] = it;
  42. ++ptr;
  43. }
  44. }
  45. FOR (it, (N * M) % K + 1, K) {
  46. FOR (i, 1, X) {
  47. assert (ptr < sz(parts));
  48. res[parts[ptr].X][parts[ptr].Y] = it;
  49. ++ptr;
  50. }
  51. }
  52. assert (ptr == sz(parts));
  53. FOR (i, 1, N) {
  54. FOR (j, 1, M) {
  55. printf("%d%c", res[i][j], j == M ? '\n' : ' ');
  56. }
  57. }
  58. return 0;
  59. }
  60.  
Time limit exceeded #stdin #stdout 5s 0KB
stdin
Standard input is empty
stdout
Standard output is empty