QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61599#1807. Distribute the BarsBooksnowWA 5ms7360kbC++141.9kb2022-11-14 11:03:352022-11-14 11:03:39

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-14 11:03:39]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:7360kb
  • [2022-11-14 11:03:35]
  • 提交

answer

#include <bits/stdc++.h>
#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 1e5 + 10, M = 4e2, lim = 1e5, mod = 998244353;
inline int read()
{
  int s = 0, w = 1;
  char ch = getchar();
  while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int n;
int c[M][M];
bool vis[N];
vector<int> pri;
vector<int> ans[N];
inline void initial()
{
  for(re int i = 2; i <= lim; i++){
    if(!vis[i]){
      pri.pb(i);
      for(re int j = 2; i * j <= lim; j++) vis[i * j] = true;
    }
  }
}
signed main()
{
  initial();
  n = read();
  if(!vis[n]) puts("-1"), exit(0);
  if(n & 1){
    int a, b;
    for(re int p : pri)
      if(n % p == 0) { a = p, b = n / p; break; }
    vector<pii> rec;
    int m = a * (b - a), k = 0;
    for(re int i = 1, j = m; i <= m / 2; i++, j--) rec.pb(mk(i * 2 - 1, j * 2 - 1));
    for(re pii x : rec) ans[k].pb(x.st), ans[k].pb(x.nd), k = (k + 1) % a;
    for(re int i = m + 1, x = 1, y = 1; i <= n; i++){
      c[x][y] = i * 2 - 1, y += 1;
      if(y > a) x += 1, y = 1;
    }
    for(re int i = 1; i <= a; i++){ //进行分组
      int x = 1, y = i, id = i - 1;
      for(re int j = 1; j <= a; j++){
        ans[id].pb(c[x][y]), x += 1, y += 1;
        if(y > a) y = 1;
      }
    }
    printf("%lld\n", a);
    for(re int i = 0; i < a; i++, puts(""))
      for(re int x : ans[i]) printf("%lld ", x);
  }
  else{
    printf("%lld\n", n / 2);
    for(re int i = 1, j = n; i <= n / 2; i++, j--)
      printf("2 %lld %lld\n", (i * 2 - 1), (j * 2 - 1));
  }
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6448kb

input:

4

output:

2
2 1 7
2 3 5

result:

ok OK (2 groups)

Test #2:

score: 0
Accepted
time: 5ms
memory: 6256kb

input:

2

output:

-1

result:

ok OK (impossible)

Test #3:

score: 0
Accepted
time: 5ms
memory: 6028kb

input:

3

output:

-1

result:

ok OK (impossible)

Test #4:

score: -100
Wrong Answer
time: 5ms
memory: 7360kb

input:

1659

output:

3
1 3299 7 3293 13 3287 19 3281 25 3275 31 3269 37 3263 43 3257 49 3251 55 3245 61 3239 67 3233 73 3227 79 3221 85 3215 91 3209 97 3203 103 3197 109 3191 115 3185 121 3179 127 3173 133 3167 139 3161 145 3155 151 3149 157 3143 163 3137 169 3131 175 3125 181 3119 187 3113 193 3107 199 3101 205 3095 21...

result:

wrong answer Not all bars are distributed