3 条题解

  • 0
    @ 2024-10-1 8:14:58

    世界上最好的题解

        #include <iostream>
        #include <algorithm>
        #include <cstring>
        #define int long long
    
        using namespace std;
        const int N = 5e6 + 10;
        int a[N];
        inline void solve()
        {
            int t;
            cin >> t;
            int num = 1;
            while (t -- )
            {  
                
                int nx;
                cin >> nx;
                for (int i = 1 ; i <= nx ; i ++ )
                {
                    char temp;
                    cin >> temp;
                    a[i] = temp - '0';
                    a[i] = a[i - 1] + a[i];
                }
    
                int ans = 0;
                int n;
                if (nx & 1) n = nx + 1;
                else n = nx;
                for (int i = 1 ; i <= n / 2 ; i ++ )
                {
                    int temp = a[i + n / 2 - 1] - a[i - 1];
                    ans = max(ans , temp);
    
                    // cout << temp << endl;
                }
                // if (num == 3) cout << ans << endl;
                for (int i = nx ; i >= nx / 2 ; i -- )
                {
                    int temp = a[i] - a[i - nx / 2];
                    ans = max(ans , temp);
    
                    // cout << temp << endl;
                }
    
    
                cout << "Case #" << num << ": " << ans << endl;
                num ++;
            }
            return ;
        }
    
        signed main()
        {
            ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
            solve();
            return 0;
        }
    
    

    信息

    ID
    5395
    时间
    1500ms
    内存
    1024MiB
    难度
    2
    标签
    递交数
    24
    已通过
    4
    上传者