QOJ.ac

QOJ

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

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:16]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:7276kb
  • [2022-11-14 11:03:15]
  • 提交

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");
  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: 5ms
memory: 7276kb

input:

4

output:

2
2 1 7
2 3 5

result:

ok OK (2 groups)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 7124kb

input:

2

output:

-1
1
2 1 3

result:

wrong output format Extra information in the output file