結果

問題 No.510 二次漸化式
ユーザー gyosib
提出日時 2017-04-29 00:19:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 1,365 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 78,820 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-09-13 19:38:16
合計ジャッジ時間 8,270 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 2
other RE * 14 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<sstream>
#include<typeinfo>

using namespace std;

void makes(vector<vector<int>> &v,vector<vector<int>> &xy, int index){
	if(index < v[0].size()){
		v[1][index] = xy[1][index-1]*v[1][index-1] + 1;
		v[0][index] = xy[0][index-1]*pow(v[1][index-1],2) + v[0][index-1];
		makes(v,xy,++index);
	}
}

vector<string> split(string &str, char sep){
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while(std::getline(ss, buffer, sep)) {
        v.push_back(buffer);
    }
    return v;
}

int main(){
	int n, q;
	cin >> n >> q;
	string query_tmp;
  vector<string> query;
  vector<vector<int>> zenka(2,vector<int>(n,0));
  vector<vector<int>> xy(2,vector<int>(n,0));
  vector<int> res;
	int a0 = 1, b0 = 1;
	zenka[0][0] = a0, zenka[1][0] = b0;

	for(int i=0;i<q;){
		cin >> query_tmp;
		query.push_back(query_tmp);
		if(query_tmp == "a" || query_tmp == "x" || query_tmp == "y") i++;
	}
	
	for(int i=0;i<query.size();i++){
		if(query[i] == "a"){
			res.push_back(zenka[0][stoi(query[++i])]);
		}else if(query[i] == "x"){
			xy[0][stoi(query[++i])] = stoi(query[++i]);
		}else if(query[i] == "y"){
			xy[1][stoi(query[++i])] = stoi(query[++i]);
		}
	
		makes(zenka,xy,1);
	}

	for(int a:res){
		cout << a << endl;
	}
	
	return 0;
}
  
0