QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#149540#5460. Sum of NumbersinvernoCompile Error//C++142.0kb2023-08-24 20:02:582023-08-24 20:03:00

Judging History

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

  • [2023-08-24 20:03:00]
  • 评测
  • [2023-08-24 20:02:58]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int N = 200050/7;
struct big{
    int n;
    short a[N];
}ans, nw;
bool inti = 1;
int n, k; 
string st;

big operator + (big a, big b) {
    int m = max(a.n, b.n);
    big c;
    c.n = m;
    c.a[1] = 0;
    for (int i = a.n + 1;i <= m;++ i) a.a[i] = 0;
    for (int i = b.n + 1;i <= m;++ i) b.a[i] = 0;
    for (int i = 1;i <= m;++ i) {
        c.a[i + 1] = 0;
        c.a[i] += a.a[i] + b.a[i];
        if (c.a[i] > 9) {
            c.a[i] -= 10;
            c.a[i+1] ++ ;
        }
    }
    if (c.a[m + 1] != 0) ++ c.n;
    return c;
}
bool operator < (big &a, big &b) {
    if (a.n != b.n) {
        return a.n < b.n;
    }
    for (int i = a.n;i >= 1;-- i) {
        if (a.a[i] != b.a[i]) 
            return (a.a[i] < b.a[i]);
    }
    return false;
}

big cp(int x, int y) {
    big c;
    c.n = 0;
    for (int i = y;i >= x;-- i) {
        c.a[++c.n] = st[i - 1] - '0';
    }
    return c;
}

void dfs(int d, int j, big nw, int len) {
    if (d == k) {
        if (abs(n - j + 1 - len) > 1) return;
        big nw2 = cp(j, n);
        nw = nw + nw2;
        
        if (inti || nw < ans) {
            ans = nw;
            inti = false;
        }
        return ;
    }
    if (j > n) return;
    for (int h = -1;h <= 1;++ h){
      int i = h + len; 
      if (i <= 0) continue;
      big nw2 = nw + cp(j,j + i - 1); //!!!
      if (j + i <= n + 1)
        dfs(d + 1, j + i, nw2, i);
    }
    return;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);=
    
    int tcase = 0;
    cin >> tcase;
    while (tcase --) {
      inti = 1;
      
      cin >> n >> k;
      ++ k;
      cin >> st;
      int L = max((int)((double)2 * n / k - (k - 1))/2,1);
      int R = min(L + k - 1, n);
      for (int i = L;i <= R;++ i) 
        dfs(2, i + 1, nw = cp(1,i), i);

      for (int i = ans.n;i >= 1;-- i) cout << ans.a[i];
      cout << endl;
    }
    return 0;
}

详细

answer.code: In function ‘int main()’:
answer.code:76:45: error: expected primary-expression before ‘=’ token
   76 |     ios::sync_with_stdio(false); cin.tie(0);=
      |                                             ^
answer.code:78:5: error: expected primary-expression before ‘int’
   78 |     int tcase = 0;
      |     ^~~
answer.code:79:12: error: ‘tcase’ was not declared in this scope
   79 |     cin >> tcase;
      |            ^~~~~