結果
| 問題 |
No.2545 Divide by 3
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2023-11-25 01:46:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 3,188 bytes |
| コンパイル時間 | 1,300 ms |
| コンパイル使用メモリ | 126,740 KB |
| 最終ジャッジ日時 | 2025-02-18 00:46:29 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
return vector<vector<T>>(n, vector<T>(m, v));
}
template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}
template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
if(v.empty()) {
cout << endl;
return;
}
for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
cout << v.back() << endl;
}
ll f(ll x){
ll ans = 0;
ll add = 0;
while(x){
ll y = x/4;
add += x-y*4;
x /= 4;
ans += x;
}
return ans+add/3;
}
void test(){
for(int i = 0; i < 1000; i++) cout << i << ":" << f(i) << ' ' << i/3 << endl;
}
using T = tuple<string, int, int, int>;
void output(vector<T> ans){
cout << ans.size() << endl;
for(auto [op, i, j, k]: ans){
if(op == "plus") cout << op << ' ' << i << ' ' << j << ' ' << k << endl;
else cout << op << ' ' << i << ' ' << j << endl;
}
}
ll test(int x, vector<T> ans){
vector<ll> a(101);
a[1] = x;
a[2] = 1;
for(auto [op, i, j, k]: ans){
if(op == "plus") {
a[i] = a[j]+a[k];
}else{
a[i] = a[j]/2;
}
// print_vector(a);
}
return a[3];
}
vector<T> solve(){
vector<T> ans;
ans.push_back({"plus", 1, 2, 1});
// a[1] <- x*(2^32)
for(int i = 0; i <= 31; i++){
ans.push_back({"plus", 1, 1, 1});
}
// a[4] <- a[1]/4
ans.push_back({"div", 4, 1, -1});
ans.push_back({"div", 4, 4, -1});
for(int i = 1; i < 20; i++){
int idx = i+4;
// a[idx] <- a[iidx-1]/4
ans.push_back({"div", idx, idx-1, -1});
ans.push_back({"div", idx, idx, -1});
}
// a[3] += a[1]/4 + a[1]/16 + ...
for(int i = 0; i < 20; i++){
int idx = i+4;
ans.push_back({"plus", 3, 3, idx});
}
// a[3];
ans.push_back({"plus", 3, 100, 100});
for(int i = 0; i <= 19; i++){
int idx = i+4;
ans.push_back({"plus", 3, 3, idx});
}
for(int i = 0; i <= 31; i++){
ans.push_back({"div", 3, 3, -1});
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
auto ans = solve();
output(ans);
// for(int i = 1; i <= 100; i++){
// ll x = i*1000;
// ll y = test(x, ans);
// cout << x << ":" << x/3 << ' ' << y << endl;
// }
}
milanis48663220