Submission #889377

#TimeUsernameProblemLanguageResultExecution timeMemory
889377AlfraganusGift (IZhO18_nicegift)C++17
0 / 100
241 ms67340 KiB
#pragma GCC optimize("unroll-loops") #pragma gcc optimize("Ofast") #pragma GCC optimization("Ofast") #pragma optimize(Ofast) #include <bits/stdc++.h> using namespace std; #define int long long #define str string #define fastio ios::sync_with_stdio(0), cin.tie(0); #define fs first #define ss second #define endl '\n' #define all(x) (x).begin(), (x).end() #define len(x) x.size() #define print(a) \ for (auto &x : a) \ cout << x << " "; \ cout << endl; #define printmp(a) \ for (auto &x : a) \ cout << x.fs << " " << x.ss << endl; const int mod = 998244353; void solve(){ int n, k; cin >> n >> k; vector<int> a(n); for(int i = 0; i < n; i ++) cin >> a[i]; int ans = 0; vector<pair<int, vector<int>>> op; while(n % k){ if(a[0] % 2 == 1 or op.size() * k >= 3e6){ cout << -1; return; } for(int j = n % k; j < n; j += k){ op.push_back({a[0] >> 1, {}}); for(int x = j; x < j + k; x ++){ a[x] -= op.back().fs; if (a[x] < 0) { cout << -1; return; } op.back().ss.push_back(x + 1); } } op.push_back({a[0] >> 1, {}}); for(int j = 0; j < n % k; j ++){ a[j] -= op.back().fs; if (a[j] < 0) { cout << -1; return; } op.back().ss.push_back(j + 1); } for(int j = n - k + n % k; j < n; j ++){ a[j] -= op.back().fs; if (a[j] < 0) { cout << -1; return; } op.back().ss.push_back(j + 1); } n = n - k + n % k; } if(a[0] > 0){ for (int j = 0; j < n; j += k) { op.push_back({a[j], {}}); for (int x = j; x < j + k; x++) { a[x] -= op.back().fs; if (a[x] < 0) { cout << -1; return; } op.back().ss.push_back(x + 1); } } } cout << op.size() << endl; for(int i = 0; i < op.size(); i ++){ cout << op[i].fs << " "; for(int j = 0; j < op[i].second.size(); j ++) cout << op[i].second[j] << ' '; cout << endl; } } signed main() { fastio int t = 1; // cin >> t; while (t--) { solve(); cout << endl; } }

Compilation message (stderr)

nicegift.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    2 | #pragma gcc optimize("Ofast")
      | 
nicegift.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization("Ofast")
      | 
nicegift.cpp:4: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    4 | #pragma optimize(Ofast)
      | 
nicegift.cpp: In function 'void solve()':
nicegift.cpp:91:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::vector<long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i = 0; i < op.size(); i ++){
      |                    ~~^~~~~~~~~~~
nicegift.cpp:93:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         for(int j = 0; j < op[i].second.size(); j ++)
      |                        ~~^~~~~~~~~~~~~~~~~~~~~
nicegift.cpp:34:9: warning: unused variable 'ans' [-Wunused-variable]
   34 |     int ans = 0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...