QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#534227#2835. Number Theory_set_Compile Error//C++172.2kb2024-08-26 22:12:582024-08-26 22:12:58

Judging History

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

  • [2024-08-26 22:12:58]
  • 评测
  • [2024-08-26 22:12:58]
  • 提交

answer

//?
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse4,sse4.1,sse4.2,ssse3,sse3,sse2,sse,avx2,avx,popcnt,abm,mmx,tune=native")
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
 
using namespace std;
 
const int N = 5155;
int n;
char str[N];
int t[N], f[10 * N][2], h[10 * N][2];
 
int reduce(int x) {
  x %= 10;
  return x < 0 ? x + 10 : x;
}
 
int dv(int x) {
  if (x >= 0)
    return x / 10;
  x = -x;
  return -((x - 1) / 10 + 1);
}
 
int dfs(int i, int lt, int g) {
  if (i >= n && lt == 0 && g == 0)
    return 0;
  if (i > n + 5)
    return 1 << 30;
  if (abs(g) > 5 * (n + 10 - i))
    return 1 << 30;
  if (i >= 10)
    return f[5 * N + g][1 + lt];
  int x = reduce(t[i] - lt);
  while (x - 10 >= -5 - (i == 1))
    x -= 10;
  int ans = 1 << 30;
  while (x <= 5 + (i == 1))
    ans = min(ans, abs(x) * i + dfs(i + 1, dv(x + lt), g + x)), x += 10;
  return ans;
}
 
void solve() {
  cin >> str, n = strlen(str);
  reverse(str, str + n);
  for (int i = 0; i != n; i++)
    t[i] = (str[i] - '0') * 9;
  for (int i = 0; i != n; i++)
    t[i + 1] += t[i] / 10, t[i] %= 10;
  while (t[n])
    t[n + 1] += t[n] / 10, t[n] %= 10, n++;
 
  f[5 * N][1] = 0;
  for (int e = n + 4; e >= 10; e--) {
    memset(h, 0x3f, sizeof h);
    for (int g = -5 * (n + 10 - e); g <= 5 * (n + 10 - e); g++)
      for (int lt = -1; lt <= 0; lt++) {
        int x = reduce(t[e] - lt);
        if (x - 10 >= -5)
          x -= 10;
        h[5 * N + g][1 + lt] = abs(x) * e + f[5 * N + g + x][1 + dv(lt + x)];
        x += 10;
        if (x <= 5)
          h[5 * N + g][1 + lt] = min(h[5 * N + g][1 + lt], abs(x) * e + f[5 * N + g + x][1 + dv(lt + x)]);
      }
    if (e >= n)
      h[5 * N][1] = 0;
    memcpy(f, h, sizeof h);
  }
 
  int ans = 1 << 30;
  for (int i = -5 * n - 50; i <= 5 * n + 50; i++)
    if (reduce(i) == t[0])
      ans = min(ans, dfs(1, dv(i), i));
  cout << ans << '\n';
}
 
void clear() {
  memset(t, 0, sizeof t);
  memset(f, 0x3f, sizeof f);
}
 
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
  int t;
  cin >> t;
  while (t--) {
    clear();
    solve();
  }
} 

詳細信息

In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/gthr.h:148,
                 from /usr/include/c++/13/ext/atomicity.h:35,
                 from /usr/include/c++/13/bits/ios_base.h:39,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from answer.code:7:
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:102:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  102 | __gthrw(pthread_once)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:102:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:103:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  103 | __gthrw(pthread_getspecific)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:103:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:104:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  104 | __gthrw(pthread_setspecific)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:104:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:106:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  106 | __gthrw(pthread_create)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:106:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:107:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  107 | __gthrw(pthread_join)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:107:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:108:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  108 | __gthrw(pthread_equal)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:108:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:109:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  109 | __gthrw(pthread_self)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:109:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:110:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  110 | __gthrw(pthread_detach)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:110:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:112:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  112 | __gthrw(pthread_cancel)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:112:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:114:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  114 | __gthrw(sched_yield)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:114:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:116:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  116 | __gthrw(pthread_mutex_lock)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:116:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:117:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  117 | __gthrw(pthread_mutex_trylock)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:117:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:119:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  119 | __gthrw(pthread_mutex_timedlock)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:119:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:121:1: error: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  121 | __gthrw(pthread_mutex_unlock)
      |...